From nobody Fri Jul 24 21:52:26 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C86243E00B3 for ; Thu, 23 Jul 2026 07:57:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784793482; cv=none; b=dTaOzbdCm+rhDemISkedWpFUQwlFuBj4De0XkSx2wowvSvhQ0MZ2/mjacpIgJMxmkUHJPg4nRO1okIGls2gNko32/xrXOEaMLl7kmiWhfsRB9N1DbOvKQPgzPRwpu41wF2p79Fwvj+WL2XxxYy3QOZIY8LzPH1kxndMcwFshVeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784793482; c=relaxed/simple; bh=LKOI6uSG3dL2yOV0m+FoJKGUuLse/gsfHXWoYSlA8kU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=eKx8SowG2K8F8kpABOOwEDzrcNqLnMKA/fTqj3Soke6twDUppnU17A7cw7U0zDMx20Ew1W45ndWucjI6RNQv6ri94pJDmLEf0Ruhjtwor2H+M8gVayBq+OkMZbJ31TNSHRfe6IYah0Ka5c6HlEHIMiCrisWKn4vdFCiwwfTymo4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QmQkv7qR; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QmQkv7qR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1784793480; x=1816329480; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=LKOI6uSG3dL2yOV0m+FoJKGUuLse/gsfHXWoYSlA8kU=; b=QmQkv7qRHpk8l3VxjAAJotBmK/0vt5PIzZPzRv/i1BK+F6erB7hyfUmr HTHlsgsSvtx7m0Zar72hNx4uenkjG8BuTW3B3sY8MGnQrC5JjrRvmsXOD JQXkkm5z+MJ+YAO6OjkPaEWfWTV6955GpFaOr2EEHJQ5L4hshNInhwQq2 N0RUwZY04VBr9+8A+ASiBQtB+DH+XALuwSU2bnCrFTm2B76Q/59xnH7an QhPi9I9byYPnSEf0S4i12g/1lWGocngl69ebHaZNnO4Cqi1UL5sWfRSYh VqBA0bkSnwb6uaOdFQh3jk91EKQB6qVPdj61DPA/sPRDh84kJnbkQW7cz A==; X-CSE-ConnectionGUID: HjDD+EA1Q+iGKN0M2zIczg== X-CSE-MsgGUID: JwxTAiLcQbC1X7gvp/MsLw== X-IronPort-AV: E=McAfee;i="6800,10657,11854"; a="89118941" X-IronPort-AV: E=Sophos;i="6.25,180,1779174000"; d="scan'208";a="89118941" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2026 00:58:00 -0700 X-CSE-ConnectionGUID: HmPL9I6lQD2HGVtplEbX9Q== X-CSE-MsgGUID: 2cmtYmoNQ3eTCUEW7NXEJA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,180,1779174000"; d="scan'208";a="260297709" Received: from amilburn-desk.amilburn-desk (HELO ahunter6-desk) ([10.245.244.59]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2026 00:57:57 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] i3c: master: Fix info leak and UAF in device unregister path Date: Thu, 23 Jul 2026 10:57:47 +0300 Message-ID: <20260723075747.34049-1-adrian.hunter@intel.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" i3c_master_unregister_i3c_devs() clears i3cdev->dev->desc before calling device_unregister(). During device_unregister(), device_del() emits a KOBJ_REMOVE uevent and unbinds the driver while the device descriptor is still expected to be valid. As a result, i3c_device_uevent() and a racing modalias_show() can observe a NULL desc and fall back to an uninitialized stack struct i3c_device_info, leaking kernel stack contents in the generated modalias. Driver .remove() callbacks may also encounter an unexpected NULL desc during unbind. Keep desc valid until device_unregister() has completed. Since device_unregister() drops the device reference and may free the device, take an extra reference with get_device() before unregistering. Clear desc afterwards and release the extra reference with put_device(). This preserves the release-time invariant that desc must be NULL while avoiding both the information leak and a potential use-after-free from writing desc after the device has been released. Reported-by: sashiko-bot@kernel.org Link: https://lore.kernel.org/linux-i3c/20260702190003.8BF741F000E9@smtp.ke= rnel.org/ Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter Reviewed-by: Frank Li --- drivers/i3c/master.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 659c14c2c192..433dc7531701 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -3083,11 +3083,12 @@ static void i3c_master_unregister_i3c_devs(struct i= 3c_master_controller *master) if (!i3cdev->dev) continue; =20 - i3cdev->dev->desc =3D NULL; - if (device_is_registered(&i3cdev->dev->dev)) + if (device_is_registered(&i3cdev->dev->dev)) { + get_device(&i3cdev->dev->dev); device_unregister(&i3cdev->dev->dev); - else - put_device(&i3cdev->dev->dev); + } + i3cdev->dev->desc =3D NULL; + put_device(&i3cdev->dev->dev); i3cdev->dev =3D NULL; } } --=20 2.53.0