From nobody Thu Jan 1 10:40:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C9B0C25B45 for ; Mon, 23 Oct 2023 18:33:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231362AbjJWSdL (ORCPT ); Mon, 23 Oct 2023 14:33:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231222AbjJWSdJ (ORCPT ); Mon, 23 Oct 2023 14:33:09 -0400 Received: from out.smtpout.orange.fr (out-15.smtpout.orange.fr [193.252.22.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA551B7 for ; Mon, 23 Oct 2023 11:33:05 -0700 (PDT) Received: from localhost.localdomain ([89.207.171.96]) by smtp.orange.fr with ESMTPSA id uzjXqFyhBlciauzjaqWBr8; Mon, 23 Oct 2023 20:33:03 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698085983; bh=FMjgweLhTo5SkdcoVkpbQPkyPY7V0wNxVnhTVFmu8Uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=emNSBpG/a9z3B1LDISJdjQaKSpJTUuKZpDTHiYtYZlavdx3+54rvcUgu0Cn2sHtnl 3FOcFQnp8G5lOpqX9RY0+ui+ci8ifYkIARA+gttPtI+ytelf1TlFTL80WgtS0+yRFe BAmDhOQYLMaQgpbMSW30h0IIfvUfSwQl1o3aEz/t5HqWgKGFN0G1nj+F03Prik93zi jXQ0MuoExuirfsSiR6of0Bk9z+685/GYw7SQfZM6cmnzFjt5VEKxkRk7kRUUHQRP6W sAntpAAf820X/JJyE8N0YeshMzhBqn5vqASJOvWRj679qL5D4SzO6V1RH4QTgrN9cT +VqLoqedq9CDw== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 23 Oct 2023 20:33:03 +0200 X-ME-IP: 89.207.171.96 From: Christophe JAILLET To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 1/4] ACPI: sysfs: Fix the check for a potential string truncation Date: Mon, 23 Oct 2023 20:32:54 +0200 Message-Id: <20001867d5d19c3b3e677f6020750cc232b3325b.1698081019.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" snprintf() does not return negative values on error. To know if the buffer was too small, the returned value should be compared with the length of the passed buffer. If it is bigger or equal, then the output has been truncated. Update the test for truncation accordingly. Also return -ENOMEM in such a case, as already done below in the same functions. Fixes: 8765c5ba1949 ("ACPI / scan: Rework modalias creation when "compatibl= e" is present") Signed-off-by: Christophe JAILLET --- drivers/acpi/device_sysfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 9d8e90744cb5..4deb36dccb73 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -158,8 +158,8 @@ static int create_pnp_modalias(const struct acpi_device= *acpi_dev, char *modalia return 0; =20 len =3D snprintf(modalias, size, "acpi:"); - if (len <=3D 0) - return len; + if (len >=3D size) + return -ENOMEM; =20 size -=3D len; =20 @@ -212,8 +212,8 @@ static int create_of_modalias(const struct acpi_device = *acpi_dev, char *modalias len =3D snprintf(modalias, size, "of:N%sT", (char *)buf.pointer); ACPI_FREE(buf.pointer); =20 - if (len <=3D 0) - return len; + if (len >=3D size) + return -ENOMEM; =20 of_compatible =3D acpi_dev->data.of_compatible; if (of_compatible->type =3D=3D ACPI_TYPE_PACKAGE) { --=20 2.32.0 From nobody Thu Jan 1 10:40:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6399CC25B45 for ; Mon, 23 Oct 2023 19:33:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230171AbjJWTda (ORCPT ); Mon, 23 Oct 2023 15:33:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbjJWTd3 (ORCPT ); Mon, 23 Oct 2023 15:33:29 -0400 Received: from smtp.smtpout.orange.fr (smtp-24.smtpout.orange.fr [80.12.242.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CB11B4 for ; Mon, 23 Oct 2023 12:33:26 -0700 (PDT) Received: from localhost.localdomain ([141.170.221.62]) by smtp.orange.fr with ESMTPSA id v0fzqGEQclciav0fzqWHCB; Mon, 23 Oct 2023 21:33:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698089604; bh=MlLlyO5nmPmV+Of5dabISHH05s0yAgNbg1lqfnhBiDo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=migciIycEHHxVSLdlbD0OWW2VjQcd388g4a4U6rPubKQtgb7HRtjFpJ689ZOdUYfJ M4DjVn6rYm2JxOdyf/1Iv8L43HNqSsvwlKONI+C/7GXglHEqf3PJXDuA3QavdkyrQe p0Ub2Cah2/euUBdqZnOBr/06U7KJDK+7wDHYJSYKqMN/EVMycRrdJPzEBvRfg6sLz0 ToJ4IBNGuk04t0PpFcPhck9S0I+d+73KNfWr+J7PcswUyNqVpMLLYXM5F9DJ9f2cL/ ud6XVZF0TjAnFY3ldTZLfVSVJjXUzRrKUTjGqr+mM6UaMwgZKN2dc0NXOComv7RoB8 kDofSZJzzAWWg== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 23 Oct 2023 21:33:24 +0200 X-ME-IP: 141.170.221.62 From: Christophe JAILLET To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 2/4] ACPI: sysfs: Fix a potential out-of-bound write in create_of_modalias() Date: Mon, 23 Oct 2023 21:33:16 +0200 Message-Id: <004a9aa85dcc37d112443e133c9edfd7624cd47b.1698081019.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The remaining size of the buffer used by snprintf() is not updated after the first write, so subsequent write in the 'for' loop a few lines below can write some data past the end of the 'modalias' buffer. Correctly update the remaining size. Note that this pattern is already correctly written in create_pnp_modalias(). Fixes: 8765c5ba1949 ("ACPI / scan: Rework modalias creation when "compatibl= e" is present") Signed-off-by: Christophe JAILLET --- drivers/acpi/device_sysfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 4deb36dccb73..7ec3142f3eda 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -215,6 +215,8 @@ static int create_of_modalias(const struct acpi_device = *acpi_dev, char *modalias if (len >=3D size) return -ENOMEM; =20 + size -=3D len; + of_compatible =3D acpi_dev->data.of_compatible; if (of_compatible->type =3D=3D ACPI_TYPE_PACKAGE) { nval =3D of_compatible->package.count; --=20 2.32.0 From nobody Thu Jan 1 10:40:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94750C25B48 for ; Mon, 23 Oct 2023 19:33:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230355AbjJWTdd (ORCPT ); Mon, 23 Oct 2023 15:33:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbjJWTdb (ORCPT ); Mon, 23 Oct 2023 15:33:31 -0400 Received: from smtp.smtpout.orange.fr (smtp-23.smtpout.orange.fr [80.12.242.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FFA2B4 for ; Mon, 23 Oct 2023 12:33:29 -0700 (PDT) Received: from localhost.localdomain ([141.170.221.62]) by smtp.orange.fr with ESMTPSA id v0fzqGEQclciav0g4qWHEJ; Mon, 23 Oct 2023 21:33:28 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698089608; bh=/5Qo3nS8waaAiEey/mOoHQa+DwKTxtDvbnHYmE4+GsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iP/bKu14gUhGjswtz4l38t2ht/2Tcp77Pltkl5s8fh2CbTDC3k+5SxHNQw8oSj4Q0 ImbJS7ubWWo7ZyBd+EbHnjPYcHXocTMqD42S7miGBjMv85zuknLVGSZnuFs6t+H2G+ 5aAp6lTX+7wPIfLmMt4BH3FtovjY8jktzW2yihDchkpC9t2APtudx3rPK6XLxjQ4dP 052FHs+M3uNsazOSc2hEUNk7eJ01TjzZzzwSOm9Smj/OiKPkfyTMaswnvIV+z9nHWM k26E1DIo/DfM6JyJA9UtjIDmz+9HCOnKgUvpbTwiW56ITasuxPVxfBwREJmtOE7aNh GyTo42AJXguFw== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 23 Oct 2023 21:33:28 +0200 X-ME-IP: 141.170.221.62 From: Christophe JAILLET To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 3/4] ACPI: sysfs: Remove some useless trailing NULL writes Date: Mon, 23 Oct 2023 21:33:17 +0200 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 'modalias' is only written with snprintf(), so it is already guaranteed to be NULL terminated. Remove the unneeded (but harmless) writes of a trailing '\0'. Signed-off-by: Christophe JAILLET --- drivers/acpi/device_sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 7ec3142f3eda..1cf6568a813f 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -177,7 +177,7 @@ static int create_pnp_modalias(const struct acpi_device= *acpi_dev, char *modalia len +=3D count; size -=3D count; } - modalias[len] =3D '\0'; + return len; } =20 @@ -237,7 +237,7 @@ static int create_of_modalias(const struct acpi_device = *acpi_dev, char *modalias len +=3D count; size -=3D count; } - modalias[len] =3D '\0'; + return len; } =20 --=20 2.32.0 From nobody Thu Jan 1 10:40:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72B6CC25B49 for ; Mon, 23 Oct 2023 19:33:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231270AbjJWTdf (ORCPT ); Mon, 23 Oct 2023 15:33:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230374AbjJWTdd (ORCPT ); Mon, 23 Oct 2023 15:33:33 -0400 Received: from smtp.smtpout.orange.fr (smtp-24.smtpout.orange.fr [80.12.242.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 712E694 for ; Mon, 23 Oct 2023 12:33:31 -0700 (PDT) Received: from localhost.localdomain ([141.170.221.62]) by smtp.orange.fr with ESMTPSA id v0fzqGEQclciav0g5qWHER; Mon, 23 Oct 2023 21:33:30 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698089610; bh=kOczc4xzag/NnlA9XkZf9hv4EVckr0nepjgeN8+fjfE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=R+rP9eZtOV0Gu0NgUyXgpD5G0f7Mtnczfb9ANQB6jCAf4xSPtHm9RgbLkUnE2KTiG bMzIpIpSvRY8aVNbezdI543C0GvzU2WBn/AWvO8yTCymF+IEThHhmXyh6W2hnYgjih 47nmsTCLNMt1SjjO/t++jo/H/DcBtu2tBh45kl+XeeoQpwnjyNt3woqlqbN//11jK6 CtGtMniOzX2+jIp2J6vd40m9penXIjlljjSx21ozWTrFgNdliWCUSKO7hP1+Or8TDU LKjitwJAjSQjTlfkrtnqGvNXfrsVHmTIUD5mWrnIkAGnvWaMQn4dhqj183ecjJOEyL /8FbvSHUFvyOQ== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 23 Oct 2023 21:33:30 +0200 X-ME-IP: 141.170.221.62 From: Christophe JAILLET To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 4/4] ACPI: sysfs: Remove some dead code Date: Mon, 23 Oct 2023 21:33:18 +0200 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" snprintf() never returns <0 values. So remove some dead code. Signed-off-by: Christophe JAILLET --- drivers/acpi/device_sysfs.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 1cf6568a813f..23373faa35ec 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -168,8 +168,6 @@ static int create_pnp_modalias(const struct acpi_device= *acpi_dev, char *modalia continue; =20 count =3D snprintf(&modalias[len], size, "%s:", id->id); - if (count < 0) - return -EINVAL; =20 if (count >=3D size) return -ENOMEM; @@ -228,8 +226,6 @@ static int create_of_modalias(const struct acpi_device = *acpi_dev, char *modalias for (i =3D 0; i < nval; i++, obj++) { count =3D snprintf(&modalias[len], size, "C%s", obj->string.pointer); - if (count < 0) - return -EINVAL; =20 if (count >=3D size) return -ENOMEM; --=20 2.32.0