From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796044900; b=T96zuqwYJNfIAGqdDrFMqHWNhMYrFsRwY9zdgp+7e2mMY3KUWRrm4wIcxWqR6TBZN9rE Iz1TUH0ufyOrcr8tV7+WK8BQLDDEyatwX29n1q9Y0I5/tPwqqm8ZKTFmKGl2SfRGPGC1X 29oubcDsXRYlDLK/y8Vek+vhIYLfLpfeHMyXuPE2tRyLWfZpjoItoX3HV/VGwWxJkw2gv KbxJ+f7YPNTyBg9SZraVdMVsQGu6LMaUduSIMsh56AxS6sAScyx9qTe22kSqq1u4dQane JPi1r7lwtSSCSBhoRURj1MP7BH6OFaY/FdHWJTelQvIE75ylmTDgVXYl4NL13UFMSaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796044900; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=GuY0LziU8NmT7d4XDbZ8T3dvpNocKcnEva4xGnSZB5Y=; b=tIjwq4jZnwSJvCc9644CxHRDKHHj2wl0LmrmL6aV4J0DB8YUsroibzfQ+Gz6attLCeRD O86iIAKbdGjZFASuFdzEOn6d27QzKezEGRYfcdwIH+Uc4aeASudUfrq7fLbG8Fh87JmXR W6+1EUo0GGz+Fa27Ww5U+ADjMo0sjuLoTKAocW9HCxe7F2Dxva7YKEWxfMj8Iv61pkNSJ FSEFOQKeqQx8AGPRAScflmCflU0Q2c6+uu/dqIA4+p1t5lnp0uH4JPgbJh+Ut6LOal0Kq NXbbCkQiq7NByZhAuNkWAxpeh6IHl+LFZTWVzoGuYSEobB/SAscpav3DSOSRy8Xa3JQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=h31Mi+op; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0024606A320 for ; Mon, 30 Nov 2026 13:21:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F0024606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=h31Mi+op DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796044899; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GuY0LziU8NmT7d4XDbZ8T3dvpNocKcnEva4xGnSZB5Y=; b=h31Mi+opf3M9T5WnTaqFkYFoK6c9jVkuLN6IKpz3IlUhJHAm6+uDPGkmCoGFlk232uGvwV G8RQ6X7LLG9MxtAeD2QrVGxe0pkmzR4J++gdh8fRUTCGoi3+YurzjEVbdCAipcsimvfwSP qCIWKfLVw0VGhfd1JerUjqnVVkMkw/A= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-y5pjgVPeNOOPjy-gvRy4ag-1; Mon, 30 Nov 2026 13:21:33 +0000 X-MC-Unique: y5pjgVPeNOOPjy-gvRy4ag-1 X-Mimecast-MFC-AGG-ID: y5pjgVPeNOOPjy-gvRy4ag_1796044890 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8A5E8195DE76; Mon, 30 Nov 2026 13:21:30 +0000 (UTC) Received: from poros-thinkpadp16vgen1.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7EB711801A67; Mon, 30 Nov 2026 13:21:23 +0000 (UTC) From: Petr Oros To: netdev@vger.kernel.org Cc: Petr Oros , Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Aleksandr Loktionov , Simon Horman , Michal Swiatkowski , Grzegorz Nitka , Paul Menzel , Wojciech Drewek , Marcin Szycik , Martyna Szapar-Mudlaw , Ivan Vecera , Alice Michael , Jacob Keller , Jesse Brandeburg , Patryk Holda , Rinitha S , Aaron Ma , intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH net v6 2/4] ice: do not leave switchdev mode while subfunction ports exist Date: Mon, 30 Nov 2026 14:21:04 +0100 Message-ID: <20261130132107.1177185-3-poros@redhat.com> In-Reply-To: <20261130132107.1177185-1-poros@redhat.com> References: <20261130132107.1177185-1-poros@redhat.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 ice_eswitch_mode_set() refuses a mode change only while VFs exist, but a subfunction port has a representor and a switchdev session too. devlink core usually refuses the change first, because of the devlink rate nodes the representors export, but ice exports none while DCB is active. A switch to legacy then destroys the representor xarray under the running session and the uplink stays in its switchdev configuration. Deleting the SF port afterwards frees its devlink port while it stays registered, so a later devlink port dump reads freed memory. Refuse the switch to legacy while subfunction ports exist. Check pf->dyn_ports, which only changes under the devlink instance lock held here, while ice_sf_dev_probe() can change the representor xarray without it. Found by AI code review. Reproduced on an E810-C (FW 8.1.1, ICE COMMS package 1.3.55.0) with the firmware LLDP agent off, without kernel changes: dcb ets set dev $PF tc-tsa all:ets tc-bw 0:50 1:50 prio-tc 1:1 devlink dev eswitch set pci/$BDF mode switchdev devlink port add pci/$BDF flavour pcisf pfnum 0 sfnum 88 devlink dev eswitch set pci/$BDF mode legacy The last command succeeded, the representor netdev stayed registered and promisc off no longer took effect on the PF. Deleting the SF port then returned 0 and the next devlink port list read its freed devlink port, KASAN reported a slab use after free in devlink_nl_port_fill(). With this patch the mode switch fails with "Remove all subfunction ports before changing eswitch mode", after the SF port is deleted it succeeds, and promisc off takes effect again. No kernel selftests cover this. Fixes: 977514fb0fa8 ("ice: create port representor for SF") Signed-off-by: Petr Oros --- v6: - Check pf->dyn_ports instead of the representor xarray, which ice_sf_dev_probe() can change without the devlink lock of the PF. - Refuse only the switch to legacy, so an unknown mode gets "Unknown eswitch mode" again. - The message says what deleting the SF port does after such a switch and names the use after free that the devlink port dump then hits. - New title, was "ice: do not leave switchdev mode while representors exist". - Dropped Ivan's Reviewed-by because the check changed. All after the Sashiko review of v5. v5: https://lore.kernel.org/all/20261127085714.1207361-3-poros@redhat.com/ --- drivers/net/ethernet/intel/ice/ice_eswitch.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/ethernet/intel/ice/ice_eswitch.c b/drivers/net/ethernet/intel/ice/ice_eswitch.c index 6e7bba4738989b..44ef1fcfc6e4a5 100644 --- a/drivers/net/ethernet/intel/ice/ice_eswitch.c +++ b/drivers/net/ethernet/intel/ice/ice_eswitch.c @@ -356,6 +356,13 @@ ice_eswitch_mode_set(struct devlink *devlink, u16 mode, switch (mode) { case DEVLINK_ESWITCH_MODE_LEGACY: + /* subfunction ports have representors too */ + if (!xa_empty(&pf->dyn_ports)) { + NL_SET_ERR_MSG_MOD(extack, + "Remove all subfunction ports before changing eswitch mode"); + return -EOPNOTSUPP; + } + dev_info(ice_pf_to_dev(pf), "PF %d changed eswitch mode to legacy", pf->hw.pf_id); xa_destroy(&pf->eswitch.reprs); -- 2.56.1