public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Nathan Huckleberry <nhuck@google.com>,
	nathan@kernel.org, error27@gmail.com,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev,
	llvm@lists.linux.dev, Nick Desaulniers <ndesaulniers@google.com>,
	trix@redhat.com
Subject: Re: [PATCH v3] staging: octeon: Fix return type of cvm_oct_xmit and cvm_oct_xmit_pow
Date: Thu, 15 Sep 2022 12:09:21 +0300	[thread overview]
Message-ID: <YyLrwW0qHpgxq4MK@kadam> (raw)
In-Reply-To: <b66ea89d-c62e-4772-b3d7-6e236da837af@www.fastmail.com>

On Thu, Sep 15, 2022 at 10:21:47AM +0200, Arnd Bergmann wrote:
> On Wed, Sep 14, 2022, at 11:10 PM, Nathan Huckleberry wrote:
> > The ndo_start_xmit field in net_device_ops is expected to be of type
> > netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb, struct net_device *dev).
> >
> > The mismatched return type breaks forward edge kCFI since the underlying
> > function definition does not match the function hook definition.
> >
> > The return type of cvm_oct_xmit and cvm_oct_xmit_pow should be changed
> > from int to netdev_tx_t.
> >
> > Reported-by: Dan Carpenter <error27@gmail.com>
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1703
> > Cc: llvm@lists.linux.dev
> > Signed-off-by: Nathan Huckleberry <nhuck@google.com>
> > Reviewed-by: Nathan Chancellor <nathan@kernel.org>
> >
> > ---
> >
> > Changes v1 -> v2:
> > - Update function signatures in ethernet-tx.h.
> >
> > Changes v2 -> v3:
> > - Move changes below the scissors --- so they don't show in commit msg
> > - Add reviewed-by tag
> 
> The patch looks correct to me so
> 
> Acked-by: Arnd Bergmann <arnd@arndb.de>
> 
> but I have two more general comments:
> 
> - For your changelogs, it would help to include the diagnostic message
>   from smatch that you link to.
> 
> - This has probably been discussed before, but why is this only
>   reported by smatch but by clang itself when building with CFI
>   enabled? It appears that CFI enforces stricter C++ style type
>   compatibility on enums while the warnings only catch incompatible
>   types according to the normal C11 rules.

This is not in a released version of Smatch.  I wrote the check and
attached it to the email with the bug reports but I wasn't really sure
how enums are handled in Clang. It's a gray area in the C standard.

I'll release it now since no one complained about false positives, but
yes, ideally this would be built into the compiler.

GCC does some sort of surprising things with enums and the kernel relies
on it in various places.  By default enums in GCC are unsigned int.  If
they have to store values which don't fit into unsigned int (negatives
or larger than UINT_MAX) type is adjusted to be signed or a larger type.

Also if the enum is in a struct and the type can be made smaller then
GCC will.  And example of this is in union myrs_cmd_mbox where the
enum myrs_cmd_opcode opcode only takes one byte. The SCSI_MYRB driver
relies on the struct thing and will corrupt memory if the struct is
larger than expected.  This is the only example I know of in the kernel
where this matters.

Sparse and thus Smatch default to unsigned int as well, but they won't
make the enum smaller for a struct.  There are some implications of
such as can an enum be less than zero?  If no then there is a potential
for if (err < 0) being a bug, and if yes then there is a potential for
array underflows

regards,
dan carpenter


  reply	other threads:[~2022-09-15  9:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-12 21:45 [PATCH] staging: octeon: Fix return type of cvm_oct_xmit and cvm_oct_xmit_pow Nathan Huckleberry
2022-09-13 22:33 ` Nathan Chancellor
2022-09-13 22:35   ` Nathan Chancellor
2022-09-13 23:04     ` [PATCH v2] " Nathan Huckleberry
2022-09-13 23:22       ` Nathan Chancellor
2022-09-14 21:10         ` [PATCH v3] " Nathan Huckleberry
2022-09-15  8:21           ` Arnd Bergmann
2022-09-15  9:09             ` Dan Carpenter [this message]
2022-09-15 12:03               ` Arnd Bergmann

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=YyLrwW0qHpgxq4MK@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=arnd@arndb.de \
    --cc=error27@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nhuck@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