From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <kuba@kernel.org>
Cc: <bspencer@blackberry.com>, <christophe-h.ricard@st.com>,
<davem@davemloft.net>, <dsahern@gmail.com>, <edumazet@google.com>,
<johannes.berg@intel.com>, <kaber@trash.net>,
<kuni1840@gmail.com>, <kuniyu@amazon.com>,
<netdev@vger.kernel.org>, <pabeni@redhat.com>,
<pablo@netfilter.org>
Subject: Re: [PATCH v1 net] netlink: Use copy_to_user() for optval in netlink_getsockopt().
Date: Wed, 19 Apr 2023 10:50:43 -0700 [thread overview]
Message-ID: <20230419175043.37093-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20230418203318.2053c4f9@kernel.org>
From: Jakub Kicinski <kuba@kernel.org>
Date: Tue, 18 Apr 2023 20:33:18 -0700
> On Tue, 18 Apr 2023 17:42:46 -0700 Kuniyuki Iwashima wrote:
> > Brad Spencer provided a detailed report 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.
> >
> > The options return a flag value that fits into 1 byte, but such behaviour
> > confuses users who do not strictly check the 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.
> > So, only 1 byte is set to optval.
> >
> > To avoid this behaviour, we need to use copy_to_user() or cast optval for
> > put_user().
> >
> > Now getsockopt() accepts char as optval as the flags are only 1 byte.
>
> I think it's worth doing, but it will change the return value on big
> endian, right?
Ah, I missed that point, yes. I hope big endian users always
initialise the value to avoid the tricky behaviour.
next prev parent reply other threads:[~2023-04-19 17:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-19 0:42 [PATCH v1 net] netlink: Use copy_to_user() for optval in netlink_getsockopt() Kuniyuki Iwashima
2023-04-19 3:33 ` Jakub Kicinski
2023-04-19 17:50 ` Kuniyuki Iwashima [this message]
2023-04-19 7:17 ` Johannes Berg
2023-04-19 17:52 ` Kuniyuki Iwashima
2023-04-19 19:46 ` Johannes Berg
2023-04-19 19:47 ` Johannes Berg
[not found] ` <20230419160908.5469e9bf@kernel.org>
2023-04-20 3:40 ` Kuniyuki Iwashima
2023-04-20 7:04 ` Johannes Berg
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=20230419175043.37093-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.berg@intel.com \
--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).