From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <ignat@cloudflare.com>
Cc: <alex.aring@gmail.com>, <alibuda@linux.alibaba.com>,
<davem@davemloft.net>, <dsahern@kernel.org>,
<edumazet@google.com>, <johan.hedberg@gmail.com>,
<kernel-team@cloudflare.com>, <kuba@kernel.org>,
<kuniyu@amazon.com>, <linux-bluetooth@vger.kernel.org>,
<linux-can@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-wpan@vger.kernel.org>, <luiz.dentz@gmail.com>,
<marcel@holtmann.org>, <miquel.raynal@bootlin.com>,
<mkl@pengutronix.de>, <netdev@vger.kernel.org>,
<pabeni@redhat.com>, <socketcan@hartkopp.net>,
<stefan@datenfreihafen.org>, <willemdebruijn.kernel@gmail.com>
Subject: Re: [PATCH v2 0/8] do not leave dangling sk pointers in pf->create functions
Date: Mon, 7 Oct 2024 14:57:34 -0700 [thread overview]
Message-ID: <20241007215734.72373-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20241007213502.28183-1-ignat@cloudflare.com>
> [PATCH v2 0/8] do not leave dangling sk pointers in pf->create functions
For the future patches, please specify the target tree, net or net-next.
From: Ignat Korchagin <ignat@cloudflare.com>
Date: Mon, 7 Oct 2024 22:34:54 +0100
> Some protocol family create() implementations have an error path after
> allocating the sk object and calling sock_init_data(). sock_init_data()
> attaches the allocated sk object to the sock object, provided by the
> caller.
>
> If the create() implementation errors out after calling sock_init_data(),
> it releases the allocated sk object, but the caller ends up having a
> dangling sk pointer in its sock object on return. Subsequent manipulations
> on this sock object may try to access the sk pointer, because it is not
> NULL thus creating a use-after-free scenario.
>
> While the first patch in the series should be enough to handle this
> scenario Eric Dumazet suggested that it would be a good idea to refactor
> the code for the af_packet implementation to avoid the error path, which
> leaves a dangling pointer, because it may be better for some tools like
> kmemleak. I went a bit further and tried to actually fix all the
> implementations, which could potentially leave a dangling sk pointer.
I feel patch 2-8 are net-next materials as the first patch is enough
to fix the issue.
Also, once all protocols have moved sock_init_data() after the last
failure point, we can change the patch 1's part to
err = pf->create(net, sock, protocol, kern);
if (err) {
DEBUG_NET_WARN_ON_ONCE(sock->sk);
goto out_module_put;
}
for the future protocols.
prev parent reply other threads:[~2024-10-07 21:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-07 21:34 [PATCH v2 0/8] do not leave dangling sk pointers in pf->create functions Ignat Korchagin
2024-10-07 21:34 ` [PATCH v2 1/8] net: explicitly clear the sk pointer, when pf->create fails Ignat Korchagin
2024-10-07 21:47 ` Kuniyuki Iwashima
2024-10-08 0:20 ` Jakub Kicinski
2024-10-07 21:34 ` [PATCH v2 2/8] af_packet: avoid erroring out after sock_init_data() in packet_create() Ignat Korchagin
2024-10-07 21:34 ` [PATCH v2 3/8] Bluetooth: L2CAP: do not leave dangling sk pointer on error in l2cap_sock_create() Ignat Korchagin
2024-10-07 21:34 ` [PATCH v2 4/8] Bluetooth: RFCOMM: avoid leaving dangling sk pointer in rfcomm_sock_alloc() Ignat Korchagin
2024-10-07 21:34 ` [PATCH v2 5/8] net: af_can: do not leave a dangling sk pointer in can_create() Ignat Korchagin
2024-10-08 2:37 ` Vincent MAILHOL
2024-10-08 6:52 ` Ignat Korchagin
2024-10-07 21:35 ` [PATCH v2 6/8] net: ieee802154: do not leave a dangling sk pointer in ieee802154_create() Ignat Korchagin
2024-10-08 8:12 ` Miquel Raynal
2024-10-07 21:35 ` [PATCH v2 7/8] net: inet: do not leave a dangling sk pointer in inet_create() Ignat Korchagin
2024-10-07 21:35 ` [PATCH v2 8/8] inet6: do not leave a dangling sk pointer in inet6_create() Ignat Korchagin
2024-10-07 21:57 ` 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=20241007215734.72373-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=alex.aring@gmail.com \
--cc=alibuda@linux.alibaba.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=ignat@cloudflare.com \
--cc=johan.hedberg@gmail.com \
--cc=kernel-team@cloudflare.com \
--cc=kuba@kernel.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wpan@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=miquel.raynal@bootlin.com \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=socketcan@hartkopp.net \
--cc=stefan@datenfreihafen.org \
--cc=willemdebruijn.kernel@gmail.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;
as well as URLs for NNTP newsgroup(s).