From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796300064; b=vWbWFBihOakAvecCi9BA20H5sZnNofzazl3XGUkWzPz0z2lSFZjrdzXK2bCKowxQS7Pv lMpevTnbiQ56j6vEkdX69Zzvl715G7fUajRjVxUekcxB2m66t/ZFKlS0Bp9JyJ/YHgv6H vjtHCnu7W0/ZO54FF+TJZ4pURSpocy7ddGagqLTBoJuVqbqw6Fx8TYXm3+UTbNJA2N5ZU V0kf0HbEtEuN4bZXQo+vEt3B0hBR8o7cKZo3vrFuA1iHgNZKxuZGucOL9wn59EnFB/mlb xGFZ80uEp826YJ++iMy2ilK0AhclJW8ddD5x9dm7fwS6XjOP548w5xhuSyAYZ9Ana0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796300064; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=8d3J7KO7do23c5JO0t9SrRiZNS0BdZ7/JtF0J7M4hpM=; b=MwUxxG0tE9SifCy9pXrqWaKpjVNxJtZx+p7iJ4MfruWucPWUhjnXWTwjUFCN76yzwRIo jDOw7549QZ8nHzvXuMD3VGGvGn3pzKounK6P4a9nvaXpLO0hLnuIRAH2ZVj5jERVEsu9w ds1h7rucdLp0uTgB/xYZooYmxEWsg9ot7iNPWuvTkrAHJMZ+nStWkcat6soX2skWKyELF 1XEaXlqFCMOZ0PneSbCw6BIghJswhsRYELCUf9n2rcydQBjHuxe1pjWO2mkf7lEXjVcsx 8Vz1xP4Y32YtwDJkFpBWlxFKzANd22YCAEgT3JfUUFe95j5QD+Ek54N//oC5FYgBGPg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="ey/y11d6"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF970606A339 for ; Thu, 3 Dec 2026 12:14:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ey/y11d6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71F121F00893; Thu, 3 Dec 2026 12:14:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796300064; bh=8d3J7KO7do23c5JO0t9SrRiZNS0BdZ7/JtF0J7M4hpM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ey/y11d6Ppd2/Dj/i/5cuvEG6a8IDpisLxhnVA9va5qHJXWNmBmu7zrQofSJKww1x yao+SU5vbDkv9W2w5R7UGMs3PkP2UaIOq5jx7Vp6E0Lvle6gGjVYpcneSyuIGuG9YD /4DUuRGr307UIbQkSbuIrImsXh4ygTtZLwtAc2Y7mG41FDuJEYjPFCLg/YZxWfgmBd STJxtmI8qXOuYjGqJbdjgcmtj/Y6tZBRYdiYUG8nerlVQ0ogTSZD67bLzxnbuDDh16 yPJCn1H+7OwoA05FqpuO10xQkz154rRnq33k8elF68ypxbgZG73e/5nd7K8S31Uv9q Qi5t0EdkN56yg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] RDMA/rtrs-srv: Fix potential session use-after-free on sysfs failure Reply-To: sashiko-reviews@lists.linux.dev To: "Guangshuo Li" Cc: linux-rdma@vger.kernel.org In-Reply-To: <20261203115553.2318954-1-liguangshuo@mail.sdu.edu.cn> References: <20261203115553.2318954-1-liguangshuo@mail.sdu.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 12:14:24 +0000 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] RDMA/rtrs-srv: dec_ref rollback allows re-adding deleted srv->dev -- commit be8058b540e2d69d724eccc0f72faf8f78caad2c Author: Guangshuo Li RDMA/rtrs-srv: Fix potential session use-after-free on sysfs failure This commit moves the per-path get_device(&srv->dev) into rtrs_srv_create_once_sysfs_root_folders(), removes put_device() from its error paths while decrementing srv->dev_ref on failure, and unlocks srv->paths_mutex before put_device() on teardown. > diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c b/drivers/infin= iband/ulp/rtrs/rtrs-srv-sysfs.c > index 9dd9141c86a54..938082369b158 100644 > --- a/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c > +++ b/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c [ ... ] > @@ -177,19 +177,22 @@ static int rtrs_srv_create_once_sysfs_root_folders(= struct rtrs_srv_path *srv_pat > err =3D device_add(&srv->dev); > if (err) { > pr_err("device_add(): %pe\n", ERR_PTR(err)); > - put_device(&srv->dev); > - goto unlock; > + goto dec_ref; > } > srv->kobj_paths =3D kobject_create_and_add("paths", &srv->dev.kobj); > if (!srv->kobj_paths) { > err =3D -ENOMEM; > pr_err("kobject_create_and_add(): %pe\n", ERR_PTR(err)); > device_del(&srv->dev); > - put_device(&srv->dev); > - goto unlock; > + goto dec_ref; > } > dev_set_uevent_suppress(&srv->dev, false); > kobject_uevent(&srv->dev.kobj, KOBJ_ADD); > +get_ref: > + get_device(&srv->dev); > + goto unlock; > +dec_ref: > + srv->dev_ref--; > unlock: > mutex_unlock(&srv->paths_mutex); [Severity: Medium] Can rolling back srv->dev_ref here cause device_add() to be called more than once on the same srv->dev? When kobject_create_and_add() fails, device_del(&srv->dev) runs and dec_ref resets srv->dev_ref to 0. Because srv is shared across all paths of a multi-path session, another path entering this function will see srv->dev_ref =3D=3D 0 and call device_add(&srv->dev) a second time. The driver core forbids calling device_add() more than once on a struct device: device_del() leaves dev->p allocated with dev->p->dead set and unlinks dev->p->knode_class asynchronously, so re-adding srv->dev leaves it in a broken state and can corrupt the class klist on klist_add_tail(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203115553.2318= 954-1-liguangshuo@mail.sdu.edu.cn?part=3D1