Linux Hardening
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: 15074444048@163.com, linux-hardening@vger.kernel.org
Cc: lihaojie <lihaojie@kylinos.cn>
Subject: Re: [PATCH] fortify: Use __struct_size replace __member_size
Date: Wed, 04 Dec 2024 18:18:15 +1000	[thread overview]
Message-ID: <D39D9DAB-E6DB-451A-92FB-BCF2A388069A@kernel.org> (raw)
In-Reply-To: <20241204064149.218136-1-15074444048@163.com>



On December 4, 2024 4:41:49 PM GMT+10:00, 15074444048@163.com wrote:
>From: lihaojie <lihaojie@kylinos.cn>
>
>Use __struct_size get destination size.
>
>Size of destination less of the size to be written will
>make buffer overflow, the size of destination should be
>complete.
>

I cannot understand what you mean here. Have you encountered a problem where a destination size is incorrectly calculated?

>Signed-off-by: lihaojie <lihaojie@kylinos.cn>
>---
> include/linux/fortify-string.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h
>index 0d99bf11d260..0504b2c8aab7 100644
>--- a/include/linux/fortify-string.h
>+++ b/include/linux/fortify-string.h
>@@ -277,7 +277,7 @@ extern ssize_t __real_strscpy(char *, const char *, size_t) __RENAME(sized_strsc
> __FORTIFY_INLINE ssize_t sized_strscpy(char * const POS p, const char * const POS q, size_t size)
> {
> 	/* Use string size rather than possible enclosing struct size. */
>-	const size_t p_size = __member_size(p);
>+	const size_t p_size = __struct_size(p);

No, this must not be done. (See the comment immediately above it.) We must limit the maximum write size to the length of the target buffe, not the enclosing structure that contains it.

-Kees

-- 
Kees Cook

      reply	other threads:[~2024-12-04  8:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04  6:41 [PATCH] fortify: Use __struct_size replace __member_size 15074444048
2024-12-04  8:18 ` 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=D39D9DAB-E6DB-451A-92FB-BCF2A388069A@kernel.org \
    --to=kees@kernel.org \
    --cc=15074444048@163.com \
    --cc=lihaojie@kylinos.cn \
    --cc=linux-hardening@vger.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