netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <johannes@sipsolutions.net>
Cc: <bspencer@blackberry.com>, <christophe-h.ricard@st.com>,
	<davem@davemloft.net>, <dsahern@gmail.com>, <edumazet@google.com>,
	<kaber@trash.net>, <kuba@kernel.org>, <kuni1840@gmail.com>,
	<kuniyu@amazon.com>, <netdev@vger.kernel.org>,
	<pabeni@redhat.com>, <pablo@netfilter.org>
Subject: Re: [PATCH v2 net] netlink: Use copy_to_user() for optval in netlink_getsockopt().
Date: Fri, 21 Apr 2023 10:52:23 -0700	[thread overview]
Message-ID: <20230421175223.77692-1-kuniyu@amazon.com> (raw)
In-Reply-To: <4624a731a9a222bc116364d26cfdfd8067a3acfc.camel@sipsolutions.net>

From:   Johannes Berg <johannes@sipsolutions.net>
Date:   Fri, 21 Apr 2023 09:56:37 +0200
> On Thu, 2023-04-20 at 23:33 +0000, Kuniyuki Iwashima wrote:
> > Brad Spencer provided a detailed report [0] that when calling getsockopt()
> > for AF_NETLINK, some SOL_NETLINK options set only 1 byte even though such
> > options require more than int as length.
> 
> Nit: not "more than" but "at least" (and sizeof(int), I guess).

Will change in v3.

> 
> > The options return a flag value that fits into 1 byte, but such behaviour
> > confuses users who do not initialise the variable before calling
> > getsockopt() and do not strictly check the returned value as char.
> > 
> > Currently, netlink_getsockopt() uses put_user() to copy data to optlen and
> > optval, but put_user() casts the data based on the pointer, char *optval.
> > As a result, only 1 byte is set to optval.
> 
> Maybe as a future thing, we should make the getsockopt method prototype
> have void here, so this kind of thing becomes a compilation error? That
> affects a fair number I guess, though I can't think of any socket
> options that really _should_ be just a char, so if it fails anywhere
> that might uncover additional bugs (and potentially avoid future ones)?

Ah, cool, we can uncover the same issue easily by doing so and
fix it unless the handler accepts char.

Thanks!

      reply	other threads:[~2023-04-21 17:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-20 23:33 [PATCH v2 net] netlink: Use copy_to_user() for optval in netlink_getsockopt() Kuniyuki Iwashima
2023-04-21  3:33 ` Jakub Kicinski
2023-04-21 17:50   ` Kuniyuki Iwashima
2023-04-21  7:56 ` Johannes Berg
2023-04-21 17:52   ` Kuniyuki Iwashima [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=20230421175223.77692-1-kuniyu@amazon.com \
    --to=kuniyu@amazon.com \
    --cc=bspencer@blackberry.com \
    --cc=christophe-h.ricard@st.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=edumazet@google.com \
    --cc=johannes@sipsolutions.net \
    --cc=kaber@trash.net \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.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;
as well as URLs for NNTP newsgroup(s).