From: Chuck Lever III <chuck.lever@oracle.com>
To: Kees Cook <keescook@chromium.org>
Cc: Jeff Layton <jlayton@kernel.org>,
"Gustavo A . R . Silva" <gustavoars@kernel.org>,
Linux NFS Mailing List <linux-nfs@vger.kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Tom Rix <trix@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"llvm@lists.linux.dev" <llvm@lists.linux.dev>,
"linux-hardening@vger.kernel.org"
<linux-hardening@vger.kernel.org>
Subject: Re: [PATCH v2] NFSD: Avoid clashing function prototypes
Date: Fri, 2 Dec 2022 21:41:33 +0000 [thread overview]
Message-ID: <E1D19946-29B2-4844-BD9D-F91E51222E82@oracle.com> (raw)
In-Reply-To: <20221202204854.gonna.644-kees@kernel.org>
> On Dec 2, 2022, at 3:48 PM, Kees Cook <keescook@chromium.org> wrote:
>
> When built with Control Flow Integrity, function prototypes between
> caller and function declaration must match. These mismatches are visible
> at compile time with the new -Wcast-function-type-strict in Clang[1].
>
> There were 97 warnings produced by NFS. For example:
>
> fs/nfsd/nfs4xdr.c:2228:17: warning: cast from '__be32 (*)(struct nfsd4_compoundargs *, struct nfsd4_access *)' (aka 'unsigned int (*)(struct nfsd4_compoundargs *, struct nfsd4_access *)') to 'nfsd4_dec' (aka 'unsigned int (*)(struct nfsd4_compoundargs *, void *)') converts to incompatible function type [-Wcast-function-type-strict]
> [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> The enc/dec callbacks were defined as passing "void *" as the second
> argument, but were being implicitly cast to a new type. Replace the
> argument with union nfsd4_op_u, and perform explicit member selection
> in the function body. There are no resulting binary differences.
>
> Changes were made mechanically using the following Coccinelle script,
> with minor by-hand fixes for members that didn't already match their
> existing argument name:
>
> @find@
> identifier func;
> type T, opsT;
> identifier ops, N;
> @@
>
> opsT ops[] = {
> [N] = (T) func,
> };
>
> @already_void@
> identifier find.func;
> identifier name;
> @@
>
> func(...,
> -void
> +union nfsd4_op_u
> *name)
> {
> ...
> }
>
> @proto depends on !already_void@
> identifier find.func;
> type T;
> identifier name;
> position p;
> @@
>
> func@p(...,
> T name
> ) {
> ...
> }
>
> @script:python get_member@
> type_name << proto.T;
> member;
> @@
>
> coccinelle.member = cocci.make_ident(type_name.split("_", 1)[1].split(' ',1)[0])
>
> @convert@
> identifier find.func;
> type proto.T;
> identifier proto.name;
> position proto.p;
> identifier get_member.member;
> @@
>
> func@p(...,
> - T name
> + union nfsd4_op_u *u
> ) {
> + T name = &u->member;
> ...
> }
>
> @cast@
> identifier find.func;
> type T, opsT;
> identifier ops, N;
> @@
>
> opsT ops[] = {
> [N] =
> - (T)
> func,
> };
>
> Cc: Chuck Lever <chuck.lever@oracle.com>
> Cc: Jeff Layton <jlayton@kernel.org>
> Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
> Cc: linux-nfs@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> v1: https://lore.kernel.org/lkml/20221007235406.2951724-1-keescook@chromium.org/
> v2: switch to using "union nfsd4_op_u" (chuck)
> ---
> fs/nfsd/nfs4xdr.c | 632 +++++++++++++++++++++++++++-------------------
> 1 file changed, 377 insertions(+), 255 deletions(-)
Lightly tested here and applied for v6.2. Many thanks!
--
Chuck Lever
prev parent reply other threads:[~2022-12-02 21:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-02 20:48 Kees Cook
2022-12-02 21:41 ` Chuck Lever III [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=E1D19946-29B2-4844-BD9D-F91E51222E82@oracle.com \
--to=chuck.lever@oracle.com \
--cc=gustavoars@kernel.org \
--cc=jlayton@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.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
all inboxes | Powered by JetHome®