linux-sctp.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
To: mptcp@lists.linux.dev, Mat Martineau <martineau@kernel.org>,
	 Geliang Tang <geliang@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	 Gregory Detal <gregory.detal@gmail.com>,
	 Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
	 Xin Long <lucien.xin@gmail.com>,
	Vlad Yasevich <vyasevich@gmail.com>,
	 Neil Horman <nhorman@tuxdriver.com>,
	wangweidong <wangweidong1@huawei.com>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	Vlad Yasevich <vyasevic@redhat.com>,
	 Allison Henderson <allison.henderson@oracle.com>,
	 Sowmini Varadhan <sowmini.varadhan@oracle.com>,
	 Al Viro <viro@zeniv.linux.org.uk>
Cc: Joel Granados <joel.granados@kernel.org>,
	netdev@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-sctp@vger.kernel.org,  linux-rdma@vger.kernel.org,
	rds-devel@oss.oracle.com,
	 "Matthieu Baerts (NGI0)" <matttbe@kernel.org>,
	stable@vger.kernel.org
Subject: [PATCH net 7/9] sctp: sysctl: udp_port: avoid using current->nsproxy
Date: Wed, 08 Jan 2025 16:34:35 +0100	[thread overview]
Message-ID: <20250108-net-sysctl-current-nsproxy-v1-7-5df34b2083e8@kernel.org> (raw)
In-Reply-To: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org>

As mentioned in a previous commit of this series, using the 'net'
structure via 'current' is not recommended for different reasons:

- Inconsistency: getting info from the reader's/writer's netns vs only
  from the opener's netns.

- current->nsproxy can be NULL in some cases, resulting in an 'Oops'
  (null-ptr-deref), e.g. when the current task is exiting, as spotted by
  syzbot [1] using acct(2).

The 'net' structure can be obtained from the table->data using
container_of().

Note that table->data could also be used directly, but that would
increase the size of this fix, while 'sctp.ctl_sock' still needs to be
retrieved from 'net' structure.

Fixes: 046c052b475e ("sctp: enable udp tunneling socks")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/67769ecb.050a0220.3a8527.003f.GAE@google.com [1]
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/sctp/sysctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index 9d29611621feaf0d2e8d7c923601ab374515563b..18fa4f44e8ec8c86f8415b1251ef8a2979c7f823 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -528,7 +528,7 @@ static int proc_sctp_do_auth(const struct ctl_table *ctl, int write,
 static int proc_sctp_do_udp_port(const struct ctl_table *ctl, int write,
 				 void *buffer, size_t *lenp, loff_t *ppos)
 {
-	struct net *net = current->nsproxy->net_ns;
+	struct net *net = container_of(ctl->data, struct net, sctp.udp_port);
 	unsigned int min = *(unsigned int *)ctl->extra1;
 	unsigned int max = *(unsigned int *)ctl->extra2;
 	struct ctl_table tbl;

-- 
2.47.1


  parent reply	other threads:[~2025-01-08 15:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-08 15:34 [PATCH net 0/9] net: sysctl: avoid using current->nsproxy Matthieu Baerts (NGI0)
2025-01-08 15:34 ` [PATCH net 1/9] mptcp: sysctl: avail sched: remove write access Matthieu Baerts (NGI0)
2025-01-08 16:25   ` Eric Dumazet
2025-01-08 15:34 ` [PATCH net 2/9] mptcp: sysctl: sched: avoid using current->nsproxy Matthieu Baerts (NGI0)
2025-01-08 15:34 ` [PATCH net 3/9] mptcp: sysctl: blackhole timeout: " Matthieu Baerts (NGI0)
2025-01-08 15:34 ` [PATCH net 4/9] sctp: sysctl: cookie_hmac_alg: " Matthieu Baerts (NGI0)
2025-01-08 15:34 ` [PATCH net 5/9] sctp: sysctl: rto_min/max: " Matthieu Baerts (NGI0)
2025-01-08 15:34 ` [PATCH net 6/9] sctp: sysctl: auth_enable: " Matthieu Baerts (NGI0)
2025-01-08 15:34 ` Matthieu Baerts (NGI0) [this message]
2025-01-08 15:34 ` [PATCH net 8/9] sctp: sysctl: plpmtud_probe_interval: " Matthieu Baerts (NGI0)
2025-01-08 15:34 ` [PATCH net 9/9] rds: sysctl: rds_tcp_{rcv,snd}buf: " Matthieu Baerts (NGI0)
2025-01-09 17:00 ` [PATCH net 0/9] net: sysctl: " patchwork-bot+netdevbpf

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=20250108-net-sysctl-current-nsproxy-v1-7-5df34b2083e8@kernel.org \
    --to=matttbe@kernel.org \
    --cc=allison.henderson@oracle.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=geliang@kernel.org \
    --cc=gregory.detal@gmail.com \
    --cc=horms@kernel.org \
    --cc=joel.granados@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-sctp@vger.kernel.org \
    --cc=lucien.xin@gmail.com \
    --cc=marcelo.leitner@gmail.com \
    --cc=martineau@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=pabeni@redhat.com \
    --cc=rds-devel@oss.oracle.com \
    --cc=sowmini.varadhan@oracle.com \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vyasevic@redhat.com \
    --cc=vyasevich@gmail.com \
    --cc=wangweidong1@huawei.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).