From: Jason Gunthorpe <jgg@nvidia.com>
To: Kees Cook <keescook@chromium.org>
Cc: "Leon Romanovsky" <leon@kernel.org>,
"Mark Zhang" <markzhang@nvidia.com>,
"Patrisious Haddad" <phaddad@nvidia.com>,
"Nathan Chancellor" <nathan@kernel.org>,
"Nick Desaulniers" <ndesaulniers@google.com>,
linux-rdma@vger.kernel.org, llvm@lists.linux.dev,
"Tom Rix" <trix@redhat.com>,
"Jason A. Donenfeld" <Jason@zx2c4.com>,
"Håkon Bugge" <haakon.bugge@oracle.com>,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] RDMA/cma: Distinguish between sockaddr_in and sockaddr_in6 by size
Date: Thu, 16 Feb 2023 11:59:10 -0400 [thread overview]
Message-ID: <Y+5SzsEkbXp6GBgN@nvidia.com> (raw)
In-Reply-To: <20230208232549.never.139-kees@kernel.org>
On Wed, Feb 08, 2023 at 03:25:53PM -0800, Kees Cook wrote:
> Clang can do some aggressive inlining, which provides it with greater
> visibility into the sizes of various objects that are passed into
> helpers. Specifically, compare_netdev_and_ip() can see through the type
> given to the "sa" argument, which means it can generate code for "struct
> sockaddr_in" that would have been passed to ipv6_addr_cmp() (that expects
> to operate on the larger "struct sockaddr_in6"), which would result in a
> compile-time buffer overflow condition detected by memcmp(). Logically,
> this state isn't reachable due to the sa_family assignment two callers
> above and the check in compare_netdev_and_ip(). Instead, provide a
> compile-time check on sizes so the size-mismatched code will be elided
> when inlining. Avoids the following warning from Clang:
>
> ../include/linux/fortify-string.h:652:4: error: call to '__read_overflow' declared with 'error' attribute: detected read beyond size of object (1st parameter)
> __read_overflow();
> ^
> note: In function 'cma_netevent_callback'
> note: which inlined function 'node_from_ndev_ip'
> 1 error generated.
>
> When the underlying object size is not known (e.g. with GCC and older
> Clang), the result of __builtin_object_size() is SIZE_MAX, which
> will also compile away, leaving the code as it was originally.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1687
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Leon Romanovsky <leon@kernel.org>
> Cc: Mark Zhang <markzhang@nvidia.com>
> Cc: Patrisious Haddad <phaddad@nvidia.com>
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Cc: linux-rdma@vger.kernel.org
> Cc: llvm@lists.linux.dev
> Signed-off-by: Kees Cook <keescook@chromium.org>
> Tested-by: Nathan Chancellor <nathan@kernel.org> # build
> ---
> drivers/infiniband/core/cma.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
This seems hacky, but I guess I can see why it is unreasonable for the
compiler to track the sa_family in this case.
Applied to for next
Jason
prev parent reply other threads:[~2023-02-16 15:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-08 23:25 [PATCH] RDMA/cma: Distinguish between sockaddr_in and sockaddr_in6 by size Kees Cook
2023-02-09 2:16 ` Nathan Chancellor
2023-02-16 15:59 ` Jason Gunthorpe [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=Y+5SzsEkbXp6GBgN@nvidia.com \
--to=jgg@nvidia.com \
--cc=Jason@zx2c4.com \
--cc=haakon.bugge@oracle.com \
--cc=keescook@chromium.org \
--cc=leon@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=markzhang@nvidia.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=phaddad@nvidia.com \
--cc=trix@redhat.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