From: Jeffrey E Altman <jaltman@auristor.com>
To: Su Hui <suhui@nfschina.com>,
dhowells@redhat.com, marc.dionne@auristor.com
Cc: linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] afs: Replace simple_strtoul with kstrtoul in afs_parse_address
Date: Thu, 29 May 2025 19:35:39 -0400 [thread overview]
Message-ID: <ea42a3fd-7ce8-43e0-a2d5-c5353070bfe2@auristor.com> (raw)
In-Reply-To: <20250527084916.1699109-1-suhui@nfschina.com>
[-- Attachment #1: Type: text/plain, Size: 1748 bytes --]
On 5/27/2025 4:49 AM, Su Hui wrote:
> kstrtoul() is better because simple_strtoul() ignores overflow which
> may lead to unexpected results.
>
> Signed-off-by: Su Hui<suhui@nfschina.com>
> ---
> fs/afs/addr_prefs.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/fs/afs/addr_prefs.c b/fs/afs/addr_prefs.c
> index c0384201b8fe..ae4f4b371882 100644
> --- a/fs/afs/addr_prefs.c
> +++ b/fs/afs/addr_prefs.c
> @@ -118,7 +118,10 @@ static int afs_parse_address(char *p, struct afs_addr_preference *pref)
>
> if (*p == '/') {
> p++;
> - tmp = simple_strtoul(p, &p, 10);
> + if (kstrtoul(p, 10, &tmp)) {
> + pr_warn("Invalid address\n");
> + return -EINVAL;
> + }
> if (tmp > mask) {
> pr_warn("Subnet mask too large\n");
> return -EINVAL;
> @@ -130,11 +133,6 @@ static int afs_parse_address(char *p, struct afs_addr_preference *pref)
> mask = tmp;
> }
>
> - if (*p) {
> - pr_warn("Invalid address\n");
> - return -EINVAL;
> - }
> -
> pref->subnet_mask = mask;
> return 0;
> }
Su Hui,
Thank you for the contribution but I do not believe this patch is correct.
The second block is required even if the simple_stroul() is replaced by
kstrtoul() as it protects against an input string which does not contain
the optional subnet mask but has some other characters after the address.
afs_parse_address() already has its own overflow checks following the
simple_strtoul() call which is specific to the interpretation of the
allowed subnet mask values.
Do you see an overflow condition which would not be caught by those
checks which would be caught by use of kstrtoul()?
Thanks again.
Jeffrey Altman
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4276 bytes --]
next prev parent reply other threads:[~2025-05-29 23:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-27 8:49 [PATCH] afs: Replace simple_strtoul with kstrtoul in afs_parse_address Su Hui
2025-05-29 23:35 ` Jeffrey E Altman [this message]
2025-05-30 10:29 ` Su Hui
2025-05-30 12:43 ` Jeffrey E Altman
2025-05-30 23:17 ` Su Hui
2025-05-30 9:32 ` David Howells
2025-05-30 10:42 ` Su Hui
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=ea42a3fd-7ce8-43e0-a2d5-c5353070bfe2@auristor.com \
--to=jaltman@auristor.com \
--cc=dhowells@redhat.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-afs@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.dionne@auristor.com \
--cc=suhui@nfschina.com \
/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