From: Jacob Keller <jacob.e.keller@intel.com>
To: Eric Dumazet <eric.dumazet@gmail.com>,
Mark Salyzyn <salyzyn@android.com>,
linux-kernel@vger.kernel.org
Cc: kernel-team@android.com, netdev@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Thomas Graf <tgraf@suug.ch>
Subject: Re: [PATCH] netlink: add buffer boundary checking
Date: Fri, 24 Jul 2020 14:14:25 -0700 [thread overview]
Message-ID: <8bd7695c-0012-83e9-8a5a-94a40d91d6f6@intel.com> (raw)
In-Reply-To: <09cd1829-8e41-bef5-ba5e-1c446c166778@gmail.com>
On 7/23/2020 12:35 PM, Eric Dumazet wrote:
> On 7/23/20 11:21 AM, Mark Salyzyn wrote:
>> Many of the nla_get_* inlines fail to check attribute's length before
>> copying the content resulting in possible out-of-boundary accesses.
>> Adjust the inlines to perform nla_len checking, for the most part
>> using the nla_memcpy function to faciliate since these are not
>> necessarily performance critical and do not need a likely fast path.
>>
>> Signed-off-by: Mark Salyzyn <salyzyn@android.com>
>> Cc: netdev@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> Cc: kernel-team@android.com
>> Cc: "David S. Miller" <davem@davemloft.net>
>> Cc: Jakub Kicinski <kuba@kernel.org>
>> Cc: Thomas Graf <tgraf@suug.ch>
>> Fixes: bfa83a9e03cf ("[NETLINK]: Type-safe netlink messages/attributes interface")
>> ---
>> include/net/netlink.h | 66 +++++++++++++++++++++++++++++++++++--------
>> 1 file changed, 54 insertions(+), 12 deletions(-)
>>
>> diff --git a/include/net/netlink.h b/include/net/netlink.h
>> index c0411f14fb53..11c0f153be7c 100644
>> --- a/include/net/netlink.h
>> +++ b/include/net/netlink.h
>> @@ -1538,7 +1538,11 @@ static inline int nla_put_bitfield32(struct sk_buff *skb, int attrtype,
>> */
>> static inline u32 nla_get_u32(const struct nlattr *nla)
>> {
>> - return *(u32 *) nla_data(nla);
>> + u32 tmp;
>> +
>> + nla_memcpy(&tmp, nla, sizeof(tmp));
>> +
>> + return tmp;
>
> I believe this will hide bugs, that syzbot was able to catch.
>
> Instead, you could perhaps introduce a CONFIG_DEBUG_NETLINK option,
> and add a WARN_ON_ONCE(nla_len(nla) < sizeof(u32)) so that we can detect bugs in callers.
>
>
I also think this is a better approach.
next prev parent reply other threads:[~2020-07-24 21:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-23 18:21 Mark Salyzyn
2020-07-23 19:19 ` David Miller
2020-07-23 19:35 ` Eric Dumazet
2020-07-23 20:13 ` Mark Salyzyn
2020-07-24 21:14 ` Jacob Keller [this message]
2020-07-24 21:45 ` Mark Salyzyn
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=8bd7695c-0012-83e9-8a5a-94a40d91d6f6@intel.com \
--to=jacob.e.keller@intel.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=kernel-team@android.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=salyzyn@android.com \
--cc=tgraf@suug.ch \
/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®