From: Eric Dumazet <eric.dumazet@gmail.com>
To: Kees Cook <kees@kernel.org>, Jakub Kicinski <kuba@kernel.org>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH RFC 3/5] rtnetlink: do_setlink: Use sockaddr_storage
Date: Tue, 5 Nov 2024 11:59:49 +0100 [thread overview]
Message-ID: <7a2e5da2-5122-4c73-9a94-20e7f21a26f5@gmail.com> (raw)
In-Reply-To: <20241104222513.3469025-3-kees@kernel.org>
On 11/4/24 11:25 PM, Kees Cook wrote:
> Instead of a heap allocation use a stack allocated sockaddr_storage to
> support arbitrary length addr_len value (but bounds check it against the
> maximum address length).
>
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> net/core/rtnetlink.c | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> index f0a520987085..eddd10b74f06 100644
> --- a/net/core/rtnetlink.c
> +++ b/net/core/rtnetlink.c
> @@ -2839,21 +2839,17 @@ static int do_setlink(const struct sk_buff *skb,
> }
>
> if (tb[IFLA_ADDRESS]) {
> - struct sockaddr *sa;
> - int len;
> + struct sockaddr_storage addr;
> + struct sockaddr *sa = (struct sockaddr *)&addr;
We already use too much stack space.
Please move addr into struct rtnl_newlink_tbs ?
>
> - len = sizeof(sa_family_t) + max_t(size_t, dev->addr_len,
> - sizeof(*sa));
> - sa = kmalloc(len, GFP_KERNEL);
> - if (!sa) {
> + if (dev->addr_len > sizeof(addr.__data)) {
> err = -ENOMEM;
> goto errout;
> }
> sa->sa_family = dev->type;
> - memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]),
> + memcpy(addr.__data, nla_data(tb[IFLA_ADDRESS]),
> dev->addr_len);
> err = dev_set_mac_address_user(dev, sa, extack);
> - kfree(sa);
> if (err)
> goto errout;
> status |= DO_SETLINK_MODIFIED;
next prev parent reply other threads:[~2024-11-05 10:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-04 22:25 [PATCH RFC 0/5] sockaddr usage removal Kees Cook
2024-11-04 22:25 ` [PATCH RFC 1/5] Revert "net: dev: Convert sa_data to flexible array in struct sockaddr" Kees Cook
2024-11-04 22:25 ` [PATCH RFC 2/5] net: core: dev.c confirmed to use classic sockaddr Kees Cook
2024-11-04 22:25 ` [PATCH RFC 3/5] rtnetlink: do_setlink: Use sockaddr_storage Kees Cook
2024-11-05 10:59 ` Eric Dumazet [this message]
2024-12-17 1:52 ` Kees Cook
2024-11-04 22:25 ` [PATCH RFC 4/5] net: core: Convert inet_addr_is_any() to sockaddr_storage Kees Cook
2024-11-04 22:25 ` [PATCH RFC 5/5] net: Convert proto_ops::getname " Kees Cook
2024-11-06 1:16 ` [PATCH RFC 0/5] sockaddr usage removal Jakub Kicinski
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=7a2e5da2-5122-4c73-9a94-20e7f21a26f5@gmail.com \
--to=eric.dumazet@gmail.com \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.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
all inboxes | Powered by JetHome®