From: Kees Cook <kees@kernel.org>
To: sel4@tilde.club
Cc: keescook@chromium.org, Brandon Luo <sel4@tilde.club>,
syzbot+98d3ceb7e01269e7bf4f@syzkaller.appspotmail.com,
syzbot+155274e882dcbf9885df@syzkaller.appspotmail.com,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fortify: strnlen: Call fortify_panic() only if the number of bytes read is greater than maxlen
Date: Mon, 24 Jul 2023 16:44:38 -0700 [thread overview]
Message-ID: <53423CC8-1A7E-4FD2-8F6B-83E88ABE30A5@kernel.org> (raw)
In-Reply-To: <20230724224857.2049906-1-sel4@tilde.club>
On July 24, 2023 3:48:57 PM PDT, sel4@tilde.club wrote:
>From: Brandon Luo <sel4@tilde.club>
>
>If the number of bytes read is p_size and p_size is less than maxlen,
>fortify_panic() will be called incorrectly. Only panic if the number of
>bytes read is greater than the minimum of p_size and maxlen since that is
> the argument to __real_strnlen().
>
>Reported-by: syzbot+98d3ceb7e01269e7bf4f@syzkaller.appspotmail.com
>Closes: https://lore.kernel.org/all/000000000000d8352e0600c0c804@google.com/
>
>Reported-by: syzbot+155274e882dcbf9885df@syzkaller.appspotmail.com
>Closes: https://lore.kernel.org/all/000000000000de4c2c0600c02b28@google.com/
Thanks for looking at these, but strnlen is working correctly. The problem was hfs's overread of a cast be32 when used with strscpy. See:
https://lore.kernel.org/lkml/202307182147.A5B81B67D@keescook/
-Kees
>
>Signed-off-by: Brandon Luo <sel4@tilde.club>
>---
> include/linux/fortify-string.h | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
>diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h
>index da51a83b2829..cde637f735fe 100644
>--- a/include/linux/fortify-string.h
>+++ b/include/linux/fortify-string.h
>@@ -176,8 +176,9 @@ __FORTIFY_INLINE __kernel_size_t strnlen(const char * const POS p, __kernel_size
> }
>
> /* Do not check characters beyond the end of p. */
>- ret = __real_strnlen(p, maxlen < p_size ? maxlen : p_size);
>- if (p_size <= ret && maxlen != ret)
>+ maxlen = (maxlen < p_size) ? maxlen : p_size;
>+ ret = __real_strnlen(p, maxlen);
>+ if (maxlen < ret)
> fortify_panic(__func__);
> return ret;
> }
--
Kees Cook
prev parent reply other threads:[~2023-07-24 23:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-18 10:57 [syzbot] [hfs?] kernel BUG in hfsplus_show_options syzbot
2023-07-19 1:27 ` syzbot
2023-07-19 4:18 ` Kees Cook
2023-07-24 22:48 ` [PATCH] fortify: strnlen: Call fortify_panic() only if the number of bytes read is greater than maxlen sel4
2023-07-24 23:44 ` Kees Cook [this message]
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=53423CC8-1A7E-4FD2-8F6B-83E88ABE30A5@kernel.org \
--to=kees@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sel4@tilde.club \
--cc=syzbot+155274e882dcbf9885df@syzkaller.appspotmail.com \
--cc=syzbot+98d3ceb7e01269e7bf4f@syzkaller.appspotmail.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
all inboxes | Powered by JetHome®