From: Dan Carpenter <dan.carpenter@linaro.org>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: rafael@kernel.org, lenb@kernel.org, linux-acpi@vger.kernel.org,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 2/4] ACPI: sysfs: Fix a potential out-of-bound write in create_of_modalias()
Date: Tue, 24 Oct 2023 08:55:25 +0300 [thread overview]
Message-ID: <df33bc21-4792-4395-bbe0-4c8893818f6b@kadam.mountain> (raw)
In-Reply-To: <004a9aa85dcc37d112443e133c9edfd7624cd47b.1698081019.git.christophe.jaillet@wanadoo.fr>
On Mon, Oct 23, 2023 at 09:33:16PM +0200, Christophe JAILLET wrote:
> 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 "compatible" is present")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> 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 >= size)
> return -ENOMEM;
>
> + size -= len;
> +
Yeah. This is a good bugfix but it also shows why the canonical format
is better. In the canonical format the "size - len" happens as part of
snprintf() instead of on a separate line where it can be forgotten.
len += snprintf(buf + len, size - len, "string");
Also the user space version of snprintf() can fail but the
kernel space version can't. This code is more complicated and introduces
a memory corruption bug because it is pretending that we need to check
for negatives. People (someone) sometimes (once ten years ago) tell me
that checking for negatives is important for security but actually it's
the reverse.
regards,
dan carpenter
next prev parent reply other threads:[~2023-10-24 5:55 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-23 17:24 [PATCH 0/4] ACPI: sysfs: Fix some issues in create_of_modalias() and create_pnp_modalias() Christophe JAILLET
2023-10-23 18:10 ` Christophe JAILLET
2023-10-23 18:32 ` [PATCH 1/4] ACPI: sysfs: Fix the check for a potential string truncation Christophe JAILLET
2023-10-23 19:33 ` [PATCH 2/4] ACPI: sysfs: Fix a potential out-of-bound write in create_of_modalias() Christophe JAILLET
2023-10-24 5:55 ` Dan Carpenter [this message]
2023-10-24 6:08 ` Dan Carpenter
2023-10-24 7:09 ` Dan Carpenter
2023-10-25 5:41 ` Dan Carpenter
2023-10-23 19:33 ` [PATCH 3/4] ACPI: sysfs: Remove some useless trailing NULL writes Christophe JAILLET
2023-10-23 19:33 ` [PATCH 4/4] ACPI: sysfs: Remove some dead code Christophe JAILLET
2023-10-23 20:09 ` [PATCH 0/4] ACPI: sysfs: Fix some issues in create_of_modalias() and create_pnp_modalias() Rafael J. Wysocki
2023-10-23 20:47 ` Christophe JAILLET
2023-10-23 20:47 ` Christophe JAILLET
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=df33bc21-4792-4395-bbe0-4c8893818f6b@kadam.mountain \
--to=dan.carpenter@linaro.org \
--cc=christophe.jaillet@wanadoo.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®