From edumazet at google.com Wed Jan 8 16:25:54 2025 From: edumazet at google.com (Eric Dumazet) Date: Wed, 8 Jan 2025 17:25:54 +0100 Subject: [rds-devel] [PATCH net 1/9] mptcp: sysctl: avail sched: remove write access In-Reply-To: <20250108-net-sysctl-current-nsproxy-v1-1-5df34b2083e8@kernel.org> References: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> <20250108-net-sysctl-current-nsproxy-v1-1-5df34b2083e8@kernel.org> Message-ID: On Wed, Jan 8, 2025 at 4:35?PM Matthieu Baerts (NGI0) wrote: > > 'net.mptcp.available_schedulers' sysctl knob is there to list available > schedulers, not to modify this list. > > There are then no reasons to give write access to it. > > Nothing would have been written anyway, but no errors would have been > returned, which is unexpected. > > Fixes: 73c900aa3660 ("mptcp: add net.mptcp.available_schedulers") > Cc: stable at vger.kernel.org > Reviewed-by: Mat Martineau > Signed-off-by: Matthieu Baerts (NGI0) Reviewed-by: Eric Dumazet From matttbe at kernel.org Wed Jan 8 15:34:28 2025 From: matttbe at kernel.org (Matthieu Baerts (NGI0)) Date: Wed, 08 Jan 2025 16:34:28 +0100 Subject: [rds-devel] [PATCH net 0/9] net: sysctl: avoid using current->nsproxy Message-ID: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> As pointed out by Al Viro and Eric Dumazet in [1], 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 as it is usually done. This could cause unexpected issues when other operations are done on the wrong 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' or 'pernet' structure can be obtained from the table->data using container_of(). Note that table->data could also be used directly in more places, but that would increase the size of this fix to replace all accesses via 'net'. Probably best to avoid that for fixes. Patches 2-9 remove access of net via current->nsproxy in sysfs handlers in MPTCP, SCTP and RDS. There are multiple patches doing almost the same thing, but the reason is to ease the backports. Patch 1 is not directly linked to this, but it is a small fix for MPTCP available_schedulers sysctl knob to explicitly mark it as read-only. Please note that this series does not address Al's comment [2]. In SCTP, some sysctl knobs set other sysfs-exposed variables for the min/max: two processes could then write two linked values at the same time, resulting in new values being outside the new boundaries. It would be great if SCTP developers can look at this problem. Link: https://lore.kernel.org/67769ecb.050a0220.3a8527.003f.GAE at google.com [1] Link: https://lore.kernel.org/netdev/20250105211158.GL1977892 at ZenIV/ [2] Signed-off-by: Matthieu Baerts (NGI0) --- Matthieu Baerts (NGI0) (9): mptcp: sysctl: avail sched: remove write access mptcp: sysctl: sched: avoid using current->nsproxy mptcp: sysctl: blackhole timeout: avoid using current->nsproxy sctp: sysctl: cookie_hmac_alg: avoid using current->nsproxy sctp: sysctl: rto_min/max: avoid using current->nsproxy sctp: sysctl: auth_enable: avoid using current->nsproxy sctp: sysctl: udp_port: avoid using current->nsproxy sctp: sysctl: plpmtud_probe_interval: avoid using current->nsproxy rds: sysctl: rds_tcp_{rcv,snd}buf: avoid using current->nsproxy net/mptcp/ctrl.c | 17 +++++++++-------- net/rds/tcp.c | 39 ++++++++++++++++++++++++++++++++------- net/sctp/sysctl.c | 14 ++++++++------ 3 files changed, 49 insertions(+), 21 deletions(-) --- base-commit: db78475ba0d3c66d430f7ded2388cc041078a542 change-id: 20250108-net-sysctl-current-nsproxy-672ae21a873f Best regards, -- Matthieu Baerts (NGI0) From matttbe at kernel.org Wed Jan 8 15:34:29 2025 From: matttbe at kernel.org (Matthieu Baerts (NGI0)) Date: Wed, 08 Jan 2025 16:34:29 +0100 Subject: [rds-devel] [PATCH net 1/9] mptcp: sysctl: avail sched: remove write access In-Reply-To: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> References: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> Message-ID: <20250108-net-sysctl-current-nsproxy-v1-1-5df34b2083e8@kernel.org> 'net.mptcp.available_schedulers' sysctl knob is there to list available schedulers, not to modify this list. There are then no reasons to give write access to it. Nothing would have been written anyway, but no errors would have been returned, which is unexpected. Fixes: 73c900aa3660 ("mptcp: add net.mptcp.available_schedulers") Cc: stable at vger.kernel.org Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mptcp/ctrl.c b/net/mptcp/ctrl.c index 38d8121331d4a981d4a60ebd8f6cd9482fc2b50c..d9b57fab2a13e64b6c8585e821ed5212f59f8651 100644 --- a/net/mptcp/ctrl.c +++ b/net/mptcp/ctrl.c @@ -228,7 +228,7 @@ static struct ctl_table mptcp_sysctl_table[] = { { .procname = "available_schedulers", .maxlen = MPTCP_SCHED_BUF_MAX, - .mode = 0644, + .mode = 0444, .proc_handler = proc_available_schedulers, }, { -- 2.47.1 From matttbe at kernel.org Wed Jan 8 15:34:30 2025 From: matttbe at kernel.org (Matthieu Baerts (NGI0)) Date: Wed, 08 Jan 2025 16:34:30 +0100 Subject: [rds-devel] [PATCH net 2/9] mptcp: sysctl: sched: avoid using current->nsproxy In-Reply-To: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> References: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> Message-ID: <20250108-net-sysctl-current-nsproxy-v1-2-5df34b2083e8@kernel.org> Using the 'net' structure via 'current' is not recommended for different reasons. First, if the goal is to use it to read or write per-netns data, this is inconsistent with how the "generic" sysctl entries are doing: directly by only using pointers set to the table entry, e.g. table->data. Linked to that, the per-netns data should always be obtained from the table linked to the netns it had been created for, which may not coincide with the reader's or writer's netns. Another reason is that access to current->nsproxy->netns can oops if attempted when current->nsproxy had been dropped when the current task is exiting. This is what syzbot found, when using acct(2): Oops: general protection fault, probably for non-canonical address 0xdffffc0000000005: 0000 [#1] PREEMPT SMP KASAN PTI KASAN: null-ptr-deref in range [0x0000000000000028-0x000000000000002f] CPU: 1 UID: 0 PID: 5924 Comm: syz-executor Not tainted 6.13.0-rc5-syzkaller-00004-gccb98ccef0e5 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 RIP: 0010:proc_scheduler+0xc6/0x3c0 net/mptcp/ctrl.c:125 Code: 03 42 80 3c 38 00 0f 85 fe 02 00 00 4d 8b a4 24 08 09 00 00 48 b8 00 00 00 00 00 fc ff df 49 8d 7c 24 28 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 cc 02 00 00 4d 8b 7c 24 28 48 8d 84 24 c8 00 00 RSP: 0018:ffffc900034774e8 EFLAGS: 00010206 RAX: dffffc0000000000 RBX: 1ffff9200068ee9e RCX: ffffc90003477620 RDX: 0000000000000005 RSI: ffffffff8b08f91e RDI: 0000000000000028 RBP: 0000000000000001 R08: ffffc90003477710 R09: 0000000000000040 R10: 0000000000000040 R11: 00000000726f7475 R12: 0000000000000000 R13: ffffc90003477620 R14: ffffc90003477710 R15: dffffc0000000000 FS: 0000000000000000(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fee3cd452d8 CR3: 000000007d116000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: proc_sys_call_handler+0x403/0x5d0 fs/proc/proc_sysctl.c:601 __kernel_write_iter+0x318/0xa80 fs/read_write.c:612 __kernel_write+0xf6/0x140 fs/read_write.c:632 do_acct_process+0xcb0/0x14a0 kernel/acct.c:539 acct_pin_kill+0x2d/0x100 kernel/acct.c:192 pin_kill+0x194/0x7c0 fs/fs_pin.c:44 mnt_pin_kill+0x61/0x1e0 fs/fs_pin.c:81 cleanup_mnt+0x3ac/0x450 fs/namespace.c:1366 task_work_run+0x14e/0x250 kernel/task_work.c:239 exit_task_work include/linux/task_work.h:43 [inline] do_exit+0xad8/0x2d70 kernel/exit.c:938 do_group_exit+0xd3/0x2a0 kernel/exit.c:1087 get_signal+0x2576/0x2610 kernel/signal.c:3017 arch_do_signal_or_restart+0x90/0x7e0 arch/x86/kernel/signal.c:337 exit_to_user_mode_loop kernel/entry/common.c:111 [inline] exit_to_user_mode_prepare include/linux/entry-common.h:329 [inline] __syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline] syscall_exit_to_user_mode+0x150/0x2a0 kernel/entry/common.c:218 do_syscall_64+0xda/0x250 arch/x86/entry/common.c:89 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fee3cb87a6a Code: Unable to access opcode bytes at 0x7fee3cb87a40. RSP: 002b:00007fffcccac688 EFLAGS: 00000202 ORIG_RAX: 0000000000000037 RAX: 0000000000000000 RBX: 00007fffcccac710 RCX: 00007fee3cb87a6a RDX: 0000000000000041 RSI: 0000000000000000 RDI: 0000000000000003 RBP: 0000000000000003 R08: 00007fffcccac6ac R09: 00007fffcccacac7 R10: 00007fffcccac710 R11: 0000000000000202 R12: 00007fee3cd49500 R13: 00007fffcccac6ac R14: 0000000000000000 R15: 00007fee3cd4b000 Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:proc_scheduler+0xc6/0x3c0 net/mptcp/ctrl.c:125 Code: 03 42 80 3c 38 00 0f 85 fe 02 00 00 4d 8b a4 24 08 09 00 00 48 b8 00 00 00 00 00 fc ff df 49 8d 7c 24 28 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 cc 02 00 00 4d 8b 7c 24 28 48 8d 84 24 c8 00 00 RSP: 0018:ffffc900034774e8 EFLAGS: 00010206 RAX: dffffc0000000000 RBX: 1ffff9200068ee9e RCX: ffffc90003477620 RDX: 0000000000000005 RSI: ffffffff8b08f91e RDI: 0000000000000028 RBP: 0000000000000001 R08: ffffc90003477710 R09: 0000000000000040 R10: 0000000000000040 R11: 00000000726f7475 R12: 0000000000000000 R13: ffffc90003477620 R14: ffffc90003477710 R15: dffffc0000000000 FS: 0000000000000000(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fee3cd452d8 CR3: 000000007d116000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 ---------------- Code disassembly (best guess), 1 bytes skipped: 0: 42 80 3c 38 00 cmpb $0x0,(%rax,%r15,1) 5: 0f 85 fe 02 00 00 jne 0x309 b: 4d 8b a4 24 08 09 00 mov 0x908(%r12),%r12 12: 00 13: 48 b8 00 00 00 00 00 movabs $0xdffffc0000000000,%rax 1a: fc ff df 1d: 49 8d 7c 24 28 lea 0x28(%r12),%rdi 22: 48 89 fa mov %rdi,%rdx 25: 48 c1 ea 03 shr $0x3,%rdx * 29: 80 3c 02 00 cmpb $0x0,(%rdx,%rax,1) <-- trapping instruction 2d: 0f 85 cc 02 00 00 jne 0x2ff 33: 4d 8b 7c 24 28 mov 0x28(%r12),%r15 38: 48 rex.W 39: 8d .byte 0x8d 3a: 84 24 c8 test %ah,(%rax,%rcx,8) Here with 'net.mptcp.scheduler', the 'net' structure is not really needed, because the table->data already has a pointer to the current scheduler, the only thing needed from the per-netns data. Simply use 'data', instead of getting (most of the time) the same thing, but from a longer and indirect way. Fixes: 6963c508fd7a ("mptcp: only allow set existing scheduler for net.mptcp.scheduler") Cc: stable at vger.kernel.org Reported-by: syzbot+e364f774c6f57f2c86d1 at syzkaller.appspotmail.com Closes: https://lore.kernel.org/67769ecb.050a0220.3a8527.003f.GAE at google.com Suggested-by: Al Viro Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/ctrl.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/net/mptcp/ctrl.c b/net/mptcp/ctrl.c index d9b57fab2a13e64b6c8585e821ed5212f59f8651..81c30aa02196d69c55799e5963f6591e416c8831 100644 --- a/net/mptcp/ctrl.c +++ b/net/mptcp/ctrl.c @@ -102,16 +102,15 @@ static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet) } #ifdef CONFIG_SYSCTL -static int mptcp_set_scheduler(const struct net *net, const char *name) +static int mptcp_set_scheduler(char *scheduler, const char *name) { - struct mptcp_pernet *pernet = mptcp_get_pernet(net); struct mptcp_sched_ops *sched; int ret = 0; rcu_read_lock(); sched = mptcp_sched_find(name); if (sched) - strscpy(pernet->scheduler, name, MPTCP_SCHED_NAME_MAX); + strscpy(scheduler, name, MPTCP_SCHED_NAME_MAX); else ret = -ENOENT; rcu_read_unlock(); @@ -122,7 +121,7 @@ static int mptcp_set_scheduler(const struct net *net, const char *name) static int proc_scheduler(const struct ctl_table *ctl, int write, void *buffer, size_t *lenp, loff_t *ppos) { - const struct net *net = current->nsproxy->net_ns; + char (*scheduler)[MPTCP_SCHED_NAME_MAX] = ctl->data; char val[MPTCP_SCHED_NAME_MAX]; struct ctl_table tbl = { .data = val, @@ -130,11 +129,11 @@ static int proc_scheduler(const struct ctl_table *ctl, int write, }; int ret; - strscpy(val, mptcp_get_scheduler(net), MPTCP_SCHED_NAME_MAX); + strscpy(val, *scheduler, MPTCP_SCHED_NAME_MAX); ret = proc_dostring(&tbl, write, buffer, lenp, ppos); if (write && ret == 0) - ret = mptcp_set_scheduler(net, val); + ret = mptcp_set_scheduler(*scheduler, val); return ret; } -- 2.47.1 From matttbe at kernel.org Wed Jan 8 15:34:31 2025 From: matttbe at kernel.org (Matthieu Baerts (NGI0)) Date: Wed, 08 Jan 2025 16:34:31 +0100 Subject: [rds-devel] [PATCH net 3/9] mptcp: sysctl: blackhole timeout: avoid using current->nsproxy In-Reply-To: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> References: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> Message-ID: <20250108-net-sysctl-current-nsproxy-v1-3-5df34b2083e8@kernel.org> As mentioned in the previous commit, 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 'pernet' structure can be obtained from the table->data using container_of(). Fixes: 27069e7cb3d1 ("mptcp: disable active MPTCP in case of blackhole") Cc: stable at vger.kernel.org Link: https://lore.kernel.org/67769ecb.050a0220.3a8527.003f.GAE at google.com [1] Suggested-by: Al Viro Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/ctrl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/mptcp/ctrl.c b/net/mptcp/ctrl.c index 81c30aa02196d69c55799e5963f6591e416c8831..b0dd008e2114bce65ee3906bbdc19a5a4316cefa 100644 --- a/net/mptcp/ctrl.c +++ b/net/mptcp/ctrl.c @@ -160,7 +160,9 @@ static int proc_blackhole_detect_timeout(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { - struct mptcp_pernet *pernet = mptcp_get_pernet(current->nsproxy->net_ns); + struct mptcp_pernet *pernet = container_of(table->data, + struct mptcp_pernet, + blackhole_timeout); int ret; ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); -- 2.47.1 From matttbe at kernel.org Wed Jan 8 15:34:32 2025 From: matttbe at kernel.org (Matthieu Baerts (NGI0)) Date: Wed, 08 Jan 2025 16:34:32 +0100 Subject: [rds-devel] [PATCH net 4/9] sctp: sysctl: cookie_hmac_alg: avoid using current->nsproxy In-Reply-To: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> References: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> Message-ID: <20250108-net-sysctl-current-nsproxy-v1-4-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, as this is the only member needed from the 'net' structure, but that would increase the size of this fix, to use '*data' everywhere 'net->sctp.sctp_hmac_alg' is used. Fixes: 3c68198e7511 ("sctp: Make hmac algorithm selection for cookie generation dynamic") Cc: stable at vger.kernel.org Link: https://lore.kernel.org/67769ecb.050a0220.3a8527.003f.GAE at google.com [1] Suggested-by: Al Viro Signed-off-by: Matthieu Baerts (NGI0) --- net/sctp/sysctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c index e5a5af343c4c98de1afb27359c104f5030583ac4..9848d19630a4f760238a3a2abd3ec823f012d34a 100644 --- a/net/sctp/sysctl.c +++ b/net/sctp/sysctl.c @@ -387,7 +387,8 @@ static struct ctl_table sctp_net_table[] = { static int proc_sctp_do_hmac_alg(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.sctp_hmac_alg); struct ctl_table tbl; bool changed = false; char *none = "none"; -- 2.47.1 From matttbe at kernel.org Wed Jan 8 15:34:33 2025 From: matttbe at kernel.org (Matthieu Baerts (NGI0)) Date: Wed, 08 Jan 2025 16:34:33 +0100 Subject: [rds-devel] [PATCH net 5/9] sctp: sysctl: rto_min/max: avoid using current->nsproxy In-Reply-To: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> References: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> Message-ID: <20250108-net-sysctl-current-nsproxy-v1-5-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, as this is the only member needed from the 'net' structure, but that would increase the size of this fix, to use '*data' everywhere 'net->sctp.rto_min/max' is used. Fixes: 4f3fdf3bc59c ("sctp: add check rto_min and rto_max in sysctl") Cc: stable at vger.kernel.org Link: https://lore.kernel.org/67769ecb.050a0220.3a8527.003f.GAE at google.com [1] Suggested-by: Al Viro Signed-off-by: Matthieu Baerts (NGI0) --- net/sctp/sysctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c index 9848d19630a4f760238a3a2abd3ec823f012d34a..a5285815264dfa9d88d1d71244f309448e97a506 100644 --- a/net/sctp/sysctl.c +++ b/net/sctp/sysctl.c @@ -433,7 +433,7 @@ static int proc_sctp_do_hmac_alg(const struct ctl_table *ctl, int write, static int proc_sctp_do_rto_min(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.rto_min); unsigned int min = *(unsigned int *) ctl->extra1; unsigned int max = *(unsigned int *) ctl->extra2; struct ctl_table tbl; @@ -461,7 +461,7 @@ static int proc_sctp_do_rto_min(const struct ctl_table *ctl, int write, static int proc_sctp_do_rto_max(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.rto_max); unsigned int min = *(unsigned int *) ctl->extra1; unsigned int max = *(unsigned int *) ctl->extra2; struct ctl_table tbl; -- 2.47.1 From matttbe at kernel.org Wed Jan 8 15:34:34 2025 From: matttbe at kernel.org (Matthieu Baerts (NGI0)) Date: Wed, 08 Jan 2025 16:34:34 +0100 Subject: [rds-devel] [PATCH net 6/9] sctp: sysctl: auth_enable: avoid using current->nsproxy In-Reply-To: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> References: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> Message-ID: <20250108-net-sysctl-current-nsproxy-v1-6-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: b14878ccb7fa ("net: sctp: cache auth_enable per endpoint") Cc: stable at vger.kernel.org Link: https://lore.kernel.org/67769ecb.050a0220.3a8527.003f.GAE at google.com [1] Suggested-by: Al Viro Signed-off-by: Matthieu Baerts (NGI0) --- 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 a5285815264dfa9d88d1d71244f309448e97a506..9d29611621feaf0d2e8d7c923601ab374515563b 100644 --- a/net/sctp/sysctl.c +++ b/net/sctp/sysctl.c @@ -499,7 +499,7 @@ static int proc_sctp_do_alpha_beta(const struct ctl_table *ctl, int write, static int proc_sctp_do_auth(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.auth_enable); struct ctl_table tbl; int new_value, ret; -- 2.47.1 From matttbe at kernel.org Wed Jan 8 15:34:35 2025 From: matttbe at kernel.org (Matthieu Baerts (NGI0)) Date: Wed, 08 Jan 2025 16:34:35 +0100 Subject: [rds-devel] [PATCH net 7/9] sctp: sysctl: udp_port: avoid using current->nsproxy In-Reply-To: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> References: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> Message-ID: <20250108-net-sysctl-current-nsproxy-v1-7-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 at vger.kernel.org Link: https://lore.kernel.org/67769ecb.050a0220.3a8527.003f.GAE at google.com [1] Suggested-by: Al Viro Signed-off-by: Matthieu Baerts (NGI0) --- 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 From matttbe at kernel.org Wed Jan 8 15:34:36 2025 From: matttbe at kernel.org (Matthieu Baerts (NGI0)) Date: Wed, 08 Jan 2025 16:34:36 +0100 Subject: [rds-devel] [PATCH net 8/9] sctp: sysctl: plpmtud_probe_interval: avoid using current->nsproxy In-Reply-To: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> References: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> Message-ID: <20250108-net-sysctl-current-nsproxy-v1-8-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, as this is the only member needed from the 'net' structure, but that would increase the size of this fix, to use '*data' everywhere 'net->sctp.probe_interval' is used. Fixes: d1e462a7a5f3 ("sctp: add probe_interval in sysctl and sock/asoc/transport") Cc: stable at vger.kernel.org Link: https://lore.kernel.org/67769ecb.050a0220.3a8527.003f.GAE at google.com [1] Suggested-by: Al Viro Signed-off-by: Matthieu Baerts (NGI0) --- net/sctp/sysctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c index 18fa4f44e8ec8c86f8415b1251ef8a2979c7f823..8e1e97be4df79f3245e2bbbeb0a75841abc67f58 100644 --- a/net/sctp/sysctl.c +++ b/net/sctp/sysctl.c @@ -569,7 +569,8 @@ static int proc_sctp_do_udp_port(const struct ctl_table *ctl, int write, static int proc_sctp_do_probe_interval(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.probe_interval); struct ctl_table tbl; int ret, new_value; -- 2.47.1 From matttbe at kernel.org Wed Jan 8 15:34:37 2025 From: matttbe at kernel.org (Matthieu Baerts (NGI0)) Date: Wed, 08 Jan 2025 16:34:37 +0100 Subject: [rds-devel] [PATCH net 9/9] rds: sysctl: rds_tcp_{rcv, snd}buf: avoid using current->nsproxy In-Reply-To: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> References: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> Message-ID: <20250108-net-sysctl-current-nsproxy-v1-9-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 per-netns structure can be obtained from the table->data using container_of(), then the 'net' one can be retrieved from the listen socket (if available). Fixes: c6a58ffed536 ("RDS: TCP: Add sysctl tunables for sndbuf/rcvbuf on rds-tcp socket") Cc: stable at vger.kernel.org Link: https://lore.kernel.org/67769ecb.050a0220.3a8527.003f.GAE at google.com [1] Suggested-by: Al Viro Signed-off-by: Matthieu Baerts (NGI0) --- net/rds/tcp.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/net/rds/tcp.c b/net/rds/tcp.c index 351ac1747224a3a1c8b0e297ba53cdbbcbc55401..0581c53e6517043ad6c2ad4207b26ab169989ed8 100644 --- a/net/rds/tcp.c +++ b/net/rds/tcp.c @@ -61,8 +61,10 @@ static atomic_t rds_tcp_unloading = ATOMIC_INIT(0); static struct kmem_cache *rds_tcp_conn_slab; -static int rds_tcp_skbuf_handler(const struct ctl_table *ctl, int write, - void *buffer, size_t *lenp, loff_t *fpos); +static int rds_tcp_sndbuf_handler(const struct ctl_table *ctl, int write, + void *buffer, size_t *lenp, loff_t *fpos); +static int rds_tcp_rcvbuf_handler(const struct ctl_table *ctl, int write, + void *buffer, size_t *lenp, loff_t *fpos); static int rds_tcp_min_sndbuf = SOCK_MIN_SNDBUF; static int rds_tcp_min_rcvbuf = SOCK_MIN_RCVBUF; @@ -74,7 +76,7 @@ static struct ctl_table rds_tcp_sysctl_table[] = { /* data is per-net pointer */ .maxlen = sizeof(int), .mode = 0644, - .proc_handler = rds_tcp_skbuf_handler, + .proc_handler = rds_tcp_sndbuf_handler, .extra1 = &rds_tcp_min_sndbuf, }, #define RDS_TCP_RCVBUF 1 @@ -83,7 +85,7 @@ static struct ctl_table rds_tcp_sysctl_table[] = { /* data is per-net pointer */ .maxlen = sizeof(int), .mode = 0644, - .proc_handler = rds_tcp_skbuf_handler, + .proc_handler = rds_tcp_rcvbuf_handler, .extra1 = &rds_tcp_min_rcvbuf, }, }; @@ -682,10 +684,10 @@ static void rds_tcp_sysctl_reset(struct net *net) spin_unlock_irq(&rds_tcp_conn_lock); } -static int rds_tcp_skbuf_handler(const struct ctl_table *ctl, int write, +static int rds_tcp_skbuf_handler(struct rds_tcp_net *rtn, + const struct ctl_table *ctl, int write, void *buffer, size_t *lenp, loff_t *fpos) { - struct net *net = current->nsproxy->net_ns; int err; err = proc_dointvec_minmax(ctl, write, buffer, lenp, fpos); @@ -694,11 +696,34 @@ static int rds_tcp_skbuf_handler(const struct ctl_table *ctl, int write, *(int *)(ctl->extra1)); return err; } - if (write) + + if (write && rtn->rds_tcp_listen_sock && rtn->rds_tcp_listen_sock->sk) { + struct net *net = sock_net(rtn->rds_tcp_listen_sock->sk); + rds_tcp_sysctl_reset(net); + } + return 0; } +static int rds_tcp_sndbuf_handler(const struct ctl_table *ctl, int write, + void *buffer, size_t *lenp, loff_t *fpos) +{ + struct rds_tcp_net *rtn = container_of(ctl->data, struct rds_tcp_net, + sndbuf_size); + + return rds_tcp_skbuf_handler(rtn, ctl, write, buffer, lenp, fpos); +} + +static int rds_tcp_rcvbuf_handler(const struct ctl_table *ctl, int write, + void *buffer, size_t *lenp, loff_t *fpos) +{ + struct rds_tcp_net *rtn = container_of(ctl->data, struct rds_tcp_net, + rcvbuf_size); + + return rds_tcp_skbuf_handler(rtn, ctl, write, buffer, lenp, fpos); +} + static void rds_tcp_exit(void) { rds_tcp_set_unloading(); -- 2.47.1 From patchwork-bot+netdevbpf at kernel.org Thu Jan 9 17:00:48 2025 From: patchwork-bot+netdevbpf at kernel.org (patchwork-bot+netdevbpf at kernel.org) Date: Thu, 09 Jan 2025 17:00:48 +0000 Subject: [rds-devel] [PATCH net 0/9] net: sysctl: avoid using current->nsproxy In-Reply-To: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> References: <20250108-net-sysctl-current-nsproxy-v1-0-5df34b2083e8@kernel.org> Message-ID: <173644204876.1449021.3388211513784045754.git-patchwork-notify@kernel.org> Hello: This series was applied to netdev/net.git (main) by Jakub Kicinski : On Wed, 08 Jan 2025 16:34:28 +0100 you wrote: > As pointed out by Al Viro and Eric Dumazet in [1], 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 as it is usually done. This could cause > unexpected issues when other operations are done on the wrong netns. > > [...] Here is the summary with links: - [net,1/9] mptcp: sysctl: avail sched: remove write access https://git.kernel.org/netdev/net/c/771ec78dc8b4 - [net,2/9] mptcp: sysctl: sched: avoid using current->nsproxy https://git.kernel.org/netdev/net/c/d38e26e36206 - [net,3/9] mptcp: sysctl: blackhole timeout: avoid using current->nsproxy https://git.kernel.org/netdev/net/c/92cf7a51bdae - [net,4/9] sctp: sysctl: cookie_hmac_alg: avoid using current->nsproxy https://git.kernel.org/netdev/net/c/ea62dd138391 - [net,5/9] sctp: sysctl: rto_min/max: avoid using current->nsproxy https://git.kernel.org/netdev/net/c/9fc17b76fc70 - [net,6/9] sctp: sysctl: auth_enable: avoid using current->nsproxy https://git.kernel.org/netdev/net/c/15649fd5415e - [net,7/9] sctp: sysctl: udp_port: avoid using current->nsproxy https://git.kernel.org/netdev/net/c/c10377bbc197 - [net,8/9] sctp: sysctl: plpmtud_probe_interval: avoid using current->nsproxy https://git.kernel.org/netdev/net/c/6259d2484d0c - [net,9/9] rds: sysctl: rds_tcp_{rcv,snd}buf: avoid using current->nsproxy https://git.kernel.org/netdev/net/c/7f5611cbc487 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html From allison.henderson at oracle.com Tue Jan 14 20:59:25 2025 From: allison.henderson at oracle.com (Allison Henderson) Date: Tue, 14 Jan 2025 20:59:25 +0000 Subject: [rds-devel] [PATCH] net: Convert proto_ops::getname to sockaddr_storage In-Reply-To: <20241217023417.work.145-kees@kernel.org> References: <20241217023417.work.145-kees@kernel.org> Message-ID: <00a27f75247a1f88fc213f0a363532683c33c6ac.camel@oracle.com> On Mon, 2024-12-16 at 18:34 -0800, Kees Cook wrote: > The proto_ops::getname callback was long ago backed by sockaddr_storage, > but the replacement of it for sockaddr was never done. Plumb it through > all the getname() callbacks, adjust prototypes, and fix casts. > > There are a few cases where the backing object is _not_ a sockaddr_storage > and converting it looks painful. In those cases, they use a cast to > struct sockaddr_storage. They appear well bounds-checked, so the risk > is no worse that we have currently. > > Other casts to sockaddr are removed, though to avoid spilling this > change into BPF (which becomes a much larger set of changes), cast the > sockaddr_storage instances there to sockaddr for the time being. > > In theory this could be split up into per-caller patches that add more > casts that all later get removed, but it seemed like there are few > enough callers that it seems feasible to do this in a single patch. Most > conversions are mechanical, so review should be fairly easy. (Famous > last words.) > > Signed-off-by: Kees Cook > --- > drivers/infiniband/hw/erdma/erdma_cm.h | 4 +- > drivers/infiniband/hw/usnic/usnic_transport.c | 16 +++--- > drivers/infiniband/sw/siw/siw_cm.h | 4 +- > drivers/isdn/mISDN/socket.c | 2 +- > drivers/net/ppp/pppoe.c | 4 +- > drivers/net/ppp/pptp.c | 4 +- > drivers/nvme/host/tcp.c | 2 +- > drivers/nvme/target/tcp.c | 6 +-- > drivers/scsi/iscsi_tcp.c | 18 +++---- > drivers/soc/qcom/qmi_interface.c | 2 +- > drivers/target/iscsi/iscsi_target_login.c | 51 +++++++++---------- > fs/dlm/lowcomms.c | 2 +- > fs/nfs/nfs4client.c | 4 +- > fs/ocfs2/cluster/tcp.c | 26 +++++----- > fs/smb/server/connection.h | 2 +- > fs/smb/server/mgmt/tree_connect.c | 2 +- > fs/smb/server/transport_ipc.c | 4 +- > fs/smb/server/transport_ipc.h | 4 +- > fs/smb/server/transport_tcp.c | 6 +-- > include/linux/net.h | 6 +-- > include/linux/sunrpc/clnt.h | 4 +- > include/net/inet_common.h | 2 +- > include/net/ipv6.h | 2 +- > include/net/sock.h | 3 +- > net/appletalk/ddp.c | 2 +- > net/atm/pvc.c | 2 +- > net/atm/svc.c | 2 +- > net/ax25/af_ax25.c | 4 +- > net/bluetooth/hci_sock.c | 2 +- > net/bluetooth/iso.c | 6 +-- > net/bluetooth/l2cap_sock.c | 6 +-- > net/bluetooth/rfcomm/sock.c | 3 +- > net/bluetooth/sco.c | 6 +-- > net/can/isotp.c | 3 +- > net/can/j1939/socket.c | 2 +- > net/can/raw.c | 2 +- > net/core/sock.c | 4 +- > net/ipv4/af_inet.c | 2 +- > net/ipv6/af_inet6.c | 2 +- > net/iucv/af_iucv.c | 6 +-- > net/l2tp/l2tp_ip.c | 2 +- > net/l2tp/l2tp_ip6.c | 2 +- > net/l2tp/l2tp_ppp.c | 2 +- > net/llc/af_llc.c | 2 +- > net/netlink/af_netlink.c | 4 +- > net/netrom/af_netrom.c | 4 +- > net/nfc/llcp_sock.c | 4 +- > net/packet/af_packet.c | 15 +++--- > net/phonet/socket.c | 10 ++-- > net/qrtr/af_qrtr.c | 2 +- > net/qrtr/ns.c | 2 +- > net/rds/af_rds.c | 2 +- > net/rose/af_rose.c | 4 +- > net/sctp/ipv6.c | 2 +- > net/smc/af_smc.c | 2 +- > net/smc/smc.h | 2 +- > net/smc/smc_clc.c | 2 +- > net/socket.c | 10 ++-- > net/sunrpc/clnt.c | 9 ++-- > net/sunrpc/svcsock.c | 8 +-- > net/sunrpc/xprtsock.c | 4 +- > net/tipc/socket.c | 2 +- > net/unix/af_unix.c | 9 ++-- > net/vmw_vsock/af_vsock.c | 2 +- > net/x25/af_x25.c | 2 +- > security/tomoyo/network.c | 3 +- > 66 files changed, 173 insertions(+), 173 deletions(-) > > diff --git a/drivers/infiniband/hw/erdma/erdma_cm.h b/drivers/infiniband/hw/erdma/erdma_cm.h > index a26d80770188..4e46ba491d5c 100644 > --- a/drivers/infiniband/hw/erdma/erdma_cm.h > +++ b/drivers/infiniband/hw/erdma/erdma_cm.h > @@ -141,12 +141,12 @@ struct erdma_cm_work { > > static inline int getname_peer(struct socket *s, struct sockaddr_storage *a) > { > - return s->ops->getname(s, (struct sockaddr *)a, 1); > + return s->ops->getname(s, a, 1); > } > > static inline int getname_local(struct socket *s, struct sockaddr_storage *a) > { > - return s->ops->getname(s, (struct sockaddr *)a, 0); > + return s->ops->getname(s, a, 0); > } > > int erdma_connect(struct iw_cm_id *id, struct iw_cm_conn_param *param); > diff --git a/drivers/infiniband/hw/usnic/usnic_transport.c b/drivers/infiniband/hw/usnic/usnic_transport.c > index dc37066900a5..7c38abc25671 100644 > --- a/drivers/infiniband/hw/usnic/usnic_transport.c > +++ b/drivers/infiniband/hw/usnic/usnic_transport.c > @@ -174,24 +174,24 @@ int usnic_transport_sock_get_addr(struct socket *sock, int *proto, > uint32_t *addr, uint16_t *port) > { > int err; > - struct sockaddr_in sock_addr; > + union { > + struct sockaddr_storage storage; > + struct sockaddr_in sock_addr; > + } u; > > - err = sock->ops->getname(sock, > - (struct sockaddr *)&sock_addr, > - 0); > + err = sock->ops->getname(sock, &u.storage, 0); > if (err < 0) > return err; > > - if (sock_addr.sin_family != AF_INET) > + if (u.sock_addr.sin_family != AF_INET) > return -EINVAL; > > if (proto) > *proto = sock->sk->sk_protocol; > if (port) > - *port = ntohs(((struct sockaddr_in *)&sock_addr)->sin_port); > + *port = ntohs(u.sock_addr.sin_port); > if (addr) > - *addr = ntohl(((struct sockaddr_in *) > - &sock_addr)->sin_addr.s_addr); > + *addr = ntohl(u.sock_addr.sin_addr.s_addr); > > return 0; > } > diff --git a/drivers/infiniband/sw/siw/siw_cm.h b/drivers/infiniband/sw/siw/siw_cm.h > index 7011c8a8ee7b..804559be83d4 100644 > --- a/drivers/infiniband/sw/siw/siw_cm.h > +++ b/drivers/infiniband/sw/siw/siw_cm.h > @@ -94,12 +94,12 @@ struct siw_cm_work { > > static inline int getname_peer(struct socket *s, struct sockaddr_storage *a) > { > - return s->ops->getname(s, (struct sockaddr *)a, 1); > + return s->ops->getname(s, a, 1); > } > > static inline int getname_local(struct socket *s, struct sockaddr_storage *a) > { > - return s->ops->getname(s, (struct sockaddr *)a, 0); > + return s->ops->getname(s, a, 0); > } > > static inline int ksock_recv(struct socket *sock, char *buf, size_t size, > diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c > index b215b28cad7b..2a3bcbf6d15b 100644 > --- a/drivers/isdn/mISDN/socket.c > +++ b/drivers/isdn/mISDN/socket.c > @@ -549,7 +549,7 @@ data_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len) > } > > static int > -data_sock_getname(struct socket *sock, struct sockaddr *addr, > +data_sock_getname(struct socket *sock, struct sockaddr_storage *addr, > int peer) > { > struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr; > diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c > index 2ea4f4890d23..139def6a7128 100644 > --- a/drivers/net/ppp/pppoe.c > +++ b/drivers/net/ppp/pppoe.c > @@ -717,8 +717,8 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr, > goto end; > } > > -static int pppoe_getname(struct socket *sock, struct sockaddr *uaddr, > - int peer) > +static int pppoe_getname(struct socket *sock, struct sockaddr_storage *uaddr, > + int peer) > { > int len = sizeof(struct sockaddr_pppox); > struct sockaddr_pppox sp; > diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c > index 689687bd2574..6d090008a34e 100644 > --- a/drivers/net/ppp/pptp.c > +++ b/drivers/net/ppp/pptp.c > @@ -479,8 +479,8 @@ static int pptp_connect(struct socket *sock, struct sockaddr *uservaddr, > return error; > } > > -static int pptp_getname(struct socket *sock, struct sockaddr *uaddr, > - int peer) > +static int pptp_getname(struct socket *sock, struct sockaddr_storage *uaddr, > + int peer) > { > int len = sizeof(struct sockaddr_pppox); > struct sockaddr_pppox sp; > diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c > index 28c76a3e1bd2..06853bf1ee8c 100644 > --- a/drivers/nvme/host/tcp.c > +++ b/drivers/nvme/host/tcp.c > @@ -2642,7 +2642,7 @@ static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size) > > mutex_lock(&queue->queue_lock); > > - ret = kernel_getsockname(queue->sock, (struct sockaddr *)&src_addr); > + ret = kernel_getsockname(queue->sock, &src_addr); > if (ret > 0) { > if (len > 0) > len--; /* strip trailing newline */ > diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c > index df24244fb820..87324c723ed4 100644 > --- a/drivers/nvme/target/tcp.c > +++ b/drivers/nvme/target/tcp.c > @@ -1689,13 +1689,11 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue) > struct inet_sock *inet = inet_sk(sock->sk); > int ret; > > - ret = kernel_getsockname(sock, > - (struct sockaddr *)&queue->sockaddr); > + ret = kernel_getsockname(sock, &queue->sockaddr); > if (ret < 0) > return ret; > > - ret = kernel_getpeername(sock, > - (struct sockaddr *)&queue->sockaddr_peer); > + ret = kernel_getpeername(sock, &queue->sockaddr_peer); > if (ret < 0) > return ret; > > diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c > index c708e1059638..0a457f8a5062 100644 > --- a/drivers/scsi/iscsi_tcp.c > +++ b/drivers/scsi/iscsi_tcp.c > @@ -794,7 +794,7 @@ static int iscsi_sw_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn, > struct iscsi_conn *conn = cls_conn->dd_data; > struct iscsi_sw_tcp_conn *tcp_sw_conn; > struct iscsi_tcp_conn *tcp_conn; > - struct sockaddr_in6 addr; > + struct sockaddr_storage addr; > struct socket *sock; > int rc; > > @@ -825,19 +825,16 @@ static int iscsi_sw_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn, > } > > if (param == ISCSI_PARAM_LOCAL_PORT) > - rc = kernel_getsockname(sock, > - (struct sockaddr *)&addr); > + rc = kernel_getsockname(sock, &addr); > else > - rc = kernel_getpeername(sock, > - (struct sockaddr *)&addr); > + rc = kernel_getpeername(sock, &addr); > sock_unlock: > mutex_unlock(&tcp_sw_conn->sock_lock); > iscsi_put_conn(conn->cls_conn); > if (rc < 0) > return rc; > > - return iscsi_conn_get_addr_param((struct sockaddr_storage *) > - &addr, param, buf); > + return iscsi_conn_get_addr_param(&addr, param, buf); > default: > return iscsi_conn_get_param(cls_conn, param, buf); > } > @@ -853,7 +850,7 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost, > struct iscsi_conn *conn; > struct iscsi_tcp_conn *tcp_conn; > struct iscsi_sw_tcp_conn *tcp_sw_conn; > - struct sockaddr_in6 addr; > + struct sockaddr_storage addr; > struct socket *sock; > int rc; > > @@ -883,14 +880,13 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost, > if (!sock) > rc = -ENOTCONN; > else > - rc = kernel_getsockname(sock, (struct sockaddr *)&addr); > + rc = kernel_getsockname(sock, &addr); > mutex_unlock(&tcp_sw_conn->sock_lock); > iscsi_put_conn(conn->cls_conn); > if (rc < 0) > return rc; > > - return iscsi_conn_get_addr_param((struct sockaddr_storage *) > - &addr, > + return iscsi_conn_get_addr_param(&addr, > (enum iscsi_param)param, buf); > default: > return iscsi_host_get_param(shost, param, buf); > diff --git a/drivers/soc/qcom/qmi_interface.c b/drivers/soc/qcom/qmi_interface.c > index bc6d6379d8b1..977cdf0f6598 100644 > --- a/drivers/soc/qcom/qmi_interface.c > +++ b/drivers/soc/qcom/qmi_interface.c > @@ -593,7 +593,7 @@ static struct socket *qmi_sock_create(struct qmi_handle *qmi, > if (ret < 0) > return ERR_PTR(ret); > > - ret = kernel_getsockname(sock, (struct sockaddr *)sq); > + ret = kernel_getsockname(sock, (struct sockaddr_storage *)sq); > if (ret < 0) { > sock_release(sock); > return ERR_PTR(ret); > diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c > index 90b870f234f0..9fcbfba43035 100644 > --- a/drivers/target/iscsi/iscsi_target_login.c > +++ b/drivers/target/iscsi/iscsi_target_login.c > @@ -907,8 +907,11 @@ int iscsi_target_setup_login_socket( > int iscsit_accept_np(struct iscsi_np *np, struct iscsit_conn *conn) > { > struct socket *new_sock, *sock = np->np_socket; > - struct sockaddr_in sock_in; > - struct sockaddr_in6 sock_in6; > + union { > + struct sockaddr_storage storage; > + struct sockaddr_in sock_in; > + struct sockaddr_in6 sock_in6; > + } u; > int rc; > > rc = kernel_accept(sock, &new_sock, 0); > @@ -919,47 +922,43 @@ int iscsit_accept_np(struct iscsi_np *np, struct iscsit_conn *conn) > conn->login_family = np->np_sockaddr.ss_family; > > if (np->np_sockaddr.ss_family == AF_INET6) { > - memset(&sock_in6, 0, sizeof(struct sockaddr_in6)); > + memset(&u.sock_in6, 0, sizeof(struct sockaddr_in6)); > > - rc = conn->sock->ops->getname(conn->sock, > - (struct sockaddr *)&sock_in6, 1); > + rc = conn->sock->ops->getname(conn->sock, &u.storage, 1); > if (rc >= 0) { > - if (!ipv6_addr_v4mapped(&sock_in6.sin6_addr)) { > - memcpy(&conn->login_sockaddr, &sock_in6, sizeof(sock_in6)); > + if (!ipv6_addr_v4mapped(&u.sock_in6.sin6_addr)) { > + memcpy(&conn->login_sockaddr, &u.sock_in6, sizeof(u.sock_in6)); > } else { > /* Pretend to be an ipv4 socket */ > - sock_in.sin_family = AF_INET; > - sock_in.sin_port = sock_in6.sin6_port; > - memcpy(&sock_in.sin_addr, &sock_in6.sin6_addr.s6_addr32[3], 4); > - memcpy(&conn->login_sockaddr, &sock_in, sizeof(sock_in)); > + u.sock_in.sin_family = AF_INET; > + u.sock_in.sin_port = u.sock_in6.sin6_port; > + memcpy(&u.sock_in.sin_addr, &u.sock_in6.sin6_addr.s6_addr32[3], 4); > + memcpy(&conn->login_sockaddr, &u.sock_in, sizeof(u.sock_in)); > } > } > > - rc = conn->sock->ops->getname(conn->sock, > - (struct sockaddr *)&sock_in6, 0); > + rc = conn->sock->ops->getname(conn->sock, &u.storage, 0); > if (rc >= 0) { > - if (!ipv6_addr_v4mapped(&sock_in6.sin6_addr)) { > - memcpy(&conn->local_sockaddr, &sock_in6, sizeof(sock_in6)); > + if (!ipv6_addr_v4mapped(&u.sock_in6.sin6_addr)) { > + memcpy(&conn->local_sockaddr, &u.sock_in6, sizeof(u.sock_in6)); > } else { > /* Pretend to be an ipv4 socket */ > - sock_in.sin_family = AF_INET; > - sock_in.sin_port = sock_in6.sin6_port; > - memcpy(&sock_in.sin_addr, &sock_in6.sin6_addr.s6_addr32[3], 4); > - memcpy(&conn->local_sockaddr, &sock_in, sizeof(sock_in)); > + u.sock_in.sin_family = AF_INET; > + u.sock_in.sin_port = u.sock_in6.sin6_port; > + memcpy(&u.sock_in.sin_addr, &u.sock_in6.sin6_addr.s6_addr32[3], 4); > + memcpy(&conn->local_sockaddr, &u.sock_in, sizeof(u.sock_in)); > } > } > } else { > - memset(&sock_in, 0, sizeof(struct sockaddr_in)); > + memset(&u.sock_in, 0, sizeof(struct sockaddr_in)); > > - rc = conn->sock->ops->getname(conn->sock, > - (struct sockaddr *)&sock_in, 1); > + rc = conn->sock->ops->getname(conn->sock, &u.storage, 1); > if (rc >= 0) > - memcpy(&conn->login_sockaddr, &sock_in, sizeof(sock_in)); > + memcpy(&conn->login_sockaddr, &u.sock_in, sizeof(u.sock_in)); > > - rc = conn->sock->ops->getname(conn->sock, > - (struct sockaddr *)&sock_in, 0); > + rc = conn->sock->ops->getname(conn->sock, &u.storage, 0); > if (rc >= 0) > - memcpy(&conn->local_sockaddr, &sock_in, sizeof(sock_in)); > + memcpy(&conn->local_sockaddr, &u.sock_in, sizeof(u.sock_in)); > } > > return 0; > diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c > index df40c3fd1070..7f232936e73c 100644 > --- a/fs/dlm/lowcomms.c > +++ b/fs/dlm/lowcomms.c > @@ -993,7 +993,7 @@ static int accept_from_sock(void) > > /* Get the connected socket's peer */ > memset(&peeraddr, 0, sizeof(peeraddr)); > - len = newsock->ops->getname(newsock, (struct sockaddr *)&peeraddr, 2); > + len = newsock->ops->getname(newsock, &peeraddr, 2); > if (len < 0) { > result = -ECONNABORTED; > goto accept_err; > diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c > index 83378f69b35e..a7428367a526 100644 > --- a/fs/nfs/nfs4client.c > +++ b/fs/nfs/nfs4client.c > @@ -248,7 +248,7 @@ struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init) > struct sockaddr_storage cb_addr; > struct sockaddr *sap = (struct sockaddr *)&cb_addr; > > - err = rpc_localaddr(clp->cl_rpcclient, sap, sizeof(cb_addr)); > + err = rpc_localaddr(clp->cl_rpcclient, &cb_addr, sizeof(cb_addr)); > if (err < 0) > goto error; > err = rpc_ntop(sap, buf, sizeof(buf)); > @@ -1352,7 +1352,7 @@ int nfs4_update_server(struct nfs_server *server, const char *hostname, > if (error != 0) > return error; > > - error = rpc_localaddr(clnt, localaddr, sizeof(address)); > + error = rpc_localaddr(clnt, &address, sizeof(address)); > if (error != 0) > return error; > > diff --git a/fs/ocfs2/cluster/tcp.c b/fs/ocfs2/cluster/tcp.c > index 2b8fa3e782fb..bb8ccd3a222f 100644 > --- a/fs/ocfs2/cluster/tcp.c > +++ b/fs/ocfs2/cluster/tcp.c > @@ -1779,7 +1779,10 @@ int o2net_register_hb_callbacks(void) > static int o2net_accept_one(struct socket *sock, int *more) > { > int ret; > - struct sockaddr_in sin; > + union { > + struct sockaddr_storage storage; > + struct sockaddr_in sin; > + } u; > struct socket *new_sock = NULL; > struct o2nm_node *node = NULL; > struct o2nm_node *local_node = NULL; > @@ -1815,15 +1818,14 @@ static int o2net_accept_one(struct socket *sock, int *more) > tcp_sock_set_nodelay(new_sock->sk); > tcp_sock_set_user_timeout(new_sock->sk, O2NET_TCP_USER_TIMEOUT); > > - ret = new_sock->ops->getname(new_sock, (struct sockaddr *) &sin, 1); > + ret = new_sock->ops->getname(new_sock, &u.storage, 1); > if (ret < 0) > goto out; > > - node = o2nm_get_node_by_ip(sin.sin_addr.s_addr); > + node = o2nm_get_node_by_ip(u.sin.sin_addr.s_addr); > if (node == NULL) { > - printk(KERN_NOTICE "o2net: Attempt to connect from unknown " > - "node at %pI4:%d\n", &sin.sin_addr.s_addr, > - ntohs(sin.sin_port)); > + printk(KERN_NOTICE "o2net: Attempt to connect from unknown node at %pI4:%d\n", > + &u.sin.sin_addr.s_addr, ntohs(u.sin.sin_port)); > ret = -EINVAL; > goto out; > } > @@ -1838,8 +1840,8 @@ static int o2net_accept_one(struct socket *sock, int *more) > &(local_node->nd_ipv4_address), > ntohs(local_node->nd_ipv4_port), > node->nd_name, > - node->nd_num, &sin.sin_addr.s_addr, > - ntohs(sin.sin_port)); > + node->nd_num, &u.sin.sin_addr.s_addr, > + ntohs(u.sin.sin_port)); > ret = -EINVAL; > goto out; > } > @@ -1849,8 +1851,8 @@ static int o2net_accept_one(struct socket *sock, int *more) > if (!o2hb_check_node_heartbeating_from_callback(node->nd_num)) { > mlog(ML_CONN, "attempt to connect from node '%s' at " > "%pI4:%d but it isn't heartbeating\n", > - node->nd_name, &sin.sin_addr.s_addr, > - ntohs(sin.sin_port)); > + node->nd_name, &u.sin.sin_addr.s_addr, > + ntohs(u.sin.sin_port)); > ret = -EINVAL; > goto out; > } > @@ -1866,8 +1868,8 @@ static int o2net_accept_one(struct socket *sock, int *more) > if (ret) { > printk(KERN_NOTICE "o2net: Attempt to connect from node '%s' " > "at %pI4:%d but it already has an open connection\n", > - node->nd_name, &sin.sin_addr.s_addr, > - ntohs(sin.sin_port)); > + node->nd_name, &u.sin.sin_addr.s_addr, > + ntohs(u.sin.sin_port)); > goto out; > } > > diff --git a/fs/smb/server/connection.h b/fs/smb/server/connection.h > index 8ddd5a3c7baf..35fc9f7cd0b2 100644 > --- a/fs/smb/server/connection.h > +++ b/fs/smb/server/connection.h > @@ -141,7 +141,7 @@ struct ksmbd_transport { > > #define KSMBD_TCP_RECV_TIMEOUT (7 * HZ) > #define KSMBD_TCP_SEND_TIMEOUT (5 * HZ) > -#define KSMBD_TCP_PEER_SOCKADDR(c) ((struct sockaddr *)&((c)->peer_addr)) > +#define KSMBD_TCP_PEER_SOCKADDR(c) (&((c)->peer_addr)) > > extern struct list_head conn_list; > extern struct rw_semaphore conn_list_lock; > diff --git a/fs/smb/server/mgmt/tree_connect.c b/fs/smb/server/mgmt/tree_connect.c > index ecfc57508671..06a59fb8d25b 100644 > --- a/fs/smb/server/mgmt/tree_connect.c > +++ b/fs/smb/server/mgmt/tree_connect.c > @@ -22,7 +22,7 @@ ksmbd_tree_conn_connect(struct ksmbd_work *work, const char *share_name) > struct ksmbd_tree_connect_response *resp = NULL; > struct ksmbd_share_config *sc; > struct ksmbd_tree_connect *tree_conn = NULL; > - struct sockaddr *peer_addr; > + struct sockaddr_storage *peer_addr; > struct ksmbd_conn *conn = work->conn; > struct ksmbd_session *sess = work->sess; > int ret; > diff --git a/fs/smb/server/transport_ipc.c b/fs/smb/server/transport_ipc.c > index 48cda3350e5a..b279f8f75eeb 100644 > --- a/fs/smb/server/transport_ipc.c > +++ b/fs/smb/server/transport_ipc.c > @@ -644,7 +644,7 @@ struct ksmbd_tree_connect_response * > ksmbd_ipc_tree_connect_request(struct ksmbd_session *sess, > struct ksmbd_share_config *share, > struct ksmbd_tree_connect *tree_conn, > - struct sockaddr *peer_addr) > + struct sockaddr_storage *peer_addr) > { > struct ksmbd_ipc_msg *msg; > struct ksmbd_tree_connect_request *req; > @@ -671,7 +671,7 @@ ksmbd_ipc_tree_connect_request(struct ksmbd_session *sess, > strscpy(req->share, share->name, KSMBD_REQ_MAX_SHARE_NAME); > snprintf(req->peer_addr, sizeof(req->peer_addr), "%pIS", peer_addr); > > - if (peer_addr->sa_family == AF_INET6) > + if (peer_addr->ss_family == AF_INET6) > req->flags |= KSMBD_TREE_CONN_FLAG_REQUEST_IPV6; > if (test_session_flag(sess, CIFDS_SESSION_FLAG_SMB2)) > req->flags |= KSMBD_TREE_CONN_FLAG_REQUEST_SMB2; > diff --git a/fs/smb/server/transport_ipc.h b/fs/smb/server/transport_ipc.h > index d9b6737f8cd0..840b9b1c56f6 100644 > --- a/fs/smb/server/transport_ipc.h > +++ b/fs/smb/server/transport_ipc.h > @@ -18,13 +18,13 @@ ksmbd_ipc_login_request_ext(const char *account); > struct ksmbd_session; > struct ksmbd_share_config; > struct ksmbd_tree_connect; > -struct sockaddr; > +struct __kernel_sockaddr_storage; > > struct ksmbd_tree_connect_response * > ksmbd_ipc_tree_connect_request(struct ksmbd_session *sess, > struct ksmbd_share_config *share, > struct ksmbd_tree_connect *tree_conn, > - struct sockaddr *peer_addr); > + struct __kernel_sockaddr_storage *peer_addr); > int ksmbd_ipc_tree_disconnect_request(unsigned long long session_id, > unsigned long long connect_id); > int ksmbd_ipc_logout_request(const char *account, int flags); > diff --git a/fs/smb/server/transport_tcp.c b/fs/smb/server/transport_tcp.c > index 0d9007285e30..7ab1031e554b 100644 > --- a/fs/smb/server/transport_tcp.c > +++ b/fs/smb/server/transport_tcp.c > @@ -160,9 +160,9 @@ static struct kvec *get_conn_iovec(struct tcp_transport *t, unsigned int nr_segs > return new_iov; > } > > -static unsigned short ksmbd_tcp_get_port(const struct sockaddr *sa) > +static unsigned short ksmbd_tcp_get_port(const struct sockaddr_storage *sa) > { > - switch (sa->sa_family) { > + switch (sa->ss_family) { > case AF_INET: > return ntohs(((struct sockaddr_in *)sa)->sin_port); > case AF_INET6: > @@ -182,7 +182,7 @@ static unsigned short ksmbd_tcp_get_port(const struct sockaddr *sa) > */ > static int ksmbd_tcp_new_connection(struct socket *client_sk) > { > - struct sockaddr *csin; > + struct sockaddr_storage *csin; > int rc = 0; > struct tcp_transport *t; > struct task_struct *handler; > diff --git a/include/linux/net.h b/include/linux/net.h > index b75bc534c1b3..e31baa3fb360 100644 > --- a/include/linux/net.h > +++ b/include/linux/net.h > @@ -175,7 +175,7 @@ struct proto_ops { > struct socket *newsock, > struct proto_accept_arg *arg); > int (*getname) (struct socket *sock, > - struct sockaddr *addr, > + struct sockaddr_storage *addr, > int peer); > __poll_t (*poll) (struct file *file, struct socket *sock, > struct poll_table_struct *wait); > @@ -353,8 +353,8 @@ int kernel_listen(struct socket *sock, int backlog); > int kernel_accept(struct socket *sock, struct socket **newsock, int flags); > int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen, > int flags); > -int kernel_getsockname(struct socket *sock, struct sockaddr *addr); > -int kernel_getpeername(struct socket *sock, struct sockaddr *addr); > +int kernel_getsockname(struct socket *sock, struct sockaddr_storage *addr); > +int kernel_getpeername(struct socket *sock, struct sockaddr_storage *addr); > int kernel_sock_shutdown(struct socket *sock, enum sock_shutdown_cmd how); > > /* Routine returns the IP overhead imposed by a (caller-protected) socket. */ > diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h > index 5321585c778f..8f29cede4ff3 100644 > --- a/include/linux/sunrpc/clnt.h > +++ b/include/linux/sunrpc/clnt.h > @@ -223,8 +223,8 @@ unsigned int rpc_num_bc_slots(struct rpc_clnt *); > void rpc_force_rebind(struct rpc_clnt *); > size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t); > const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t); > -int rpc_localaddr(struct rpc_clnt *, struct sockaddr *, size_t); > - > +int rpc_localaddr(struct rpc_clnt *clnt, struct sockaddr_storage *buf, > + size_t buflen); > int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt, > int (*fn)(struct rpc_clnt *, struct rpc_xprt *, void *), > void *data); > diff --git a/include/net/inet_common.h b/include/net/inet_common.h > index c17a6585d0b0..2bc95e0171e7 100644 > --- a/include/net/inet_common.h > +++ b/include/net/inet_common.h > @@ -54,7 +54,7 @@ int inet_bind_sk(struct sock *sk, struct sockaddr *uaddr, int addr_len); > #define BIND_NO_CAP_NET_BIND_SERVICE (1 << 3) > int __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len, > u32 flags); > -int inet_getname(struct socket *sock, struct sockaddr *uaddr, > +int inet_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer); > int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); > int inet_ctl_sock_create(struct sock **sk, unsigned short family, > diff --git a/include/net/ipv6.h b/include/net/ipv6.h > index 248bfb26e2af..e0ee07a8486e 100644 > --- a/include/net/ipv6.h > +++ b/include/net/ipv6.h > @@ -1214,7 +1214,7 @@ void inet6_sock_destruct(struct sock *sk); > int inet6_release(struct socket *sock); > int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len); > int inet6_bind_sk(struct sock *sk, struct sockaddr *uaddr, int addr_len); > -int inet6_getname(struct socket *sock, struct sockaddr *uaddr, > +int inet6_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer); > int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); > int inet6_compat_ioctl(struct socket *sock, unsigned int cmd, > diff --git a/include/net/sock.h b/include/net/sock.h > index 7464e9f9f47c..647edced2a51 100644 > --- a/include/net/sock.h > +++ b/include/net/sock.h > @@ -1837,7 +1837,8 @@ int sock_no_bind(struct socket *, struct sockaddr *, int); > int sock_no_connect(struct socket *, struct sockaddr *, int, int); > int sock_no_socketpair(struct socket *, struct socket *); > int sock_no_accept(struct socket *, struct socket *, struct proto_accept_arg *); > -int sock_no_getname(struct socket *, struct sockaddr *, int); > +int sock_no_getname(struct socket *sock, struct sockaddr_storage *saddr, > + int peer); > int sock_no_ioctl(struct socket *, unsigned int, unsigned long); > int sock_no_listen(struct socket *, int); > int sock_no_shutdown(struct socket *, int); > diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c > index b068651984fe..b0a5137e9dce 100644 > --- a/net/appletalk/ddp.c > +++ b/net/appletalk/ddp.c > @@ -1258,7 +1258,7 @@ static int atalk_connect(struct socket *sock, struct sockaddr *uaddr, > * Find the name of an AppleTalk socket. Just copy the right > * fields into the sockaddr. > */ > -static int atalk_getname(struct socket *sock, struct sockaddr *uaddr, > +static int atalk_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer) > { > struct sockaddr_at sat; > diff --git a/net/atm/pvc.c b/net/atm/pvc.c > index 66d9a9bd5896..897b82de7a5b 100644 > --- a/net/atm/pvc.c > +++ b/net/atm/pvc.c > @@ -86,7 +86,7 @@ static int pvc_getsockopt(struct socket *sock, int level, int optname, > return error; > } > > -static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr, > +static int pvc_getname(struct socket *sock, struct sockaddr_storage *sockaddr, > int peer) > { > struct sockaddr_atmpvc *addr; > diff --git a/net/atm/svc.c b/net/atm/svc.c > index f8137ae693b0..b02f5833cc9a 100644 > --- a/net/atm/svc.c > +++ b/net/atm/svc.c > @@ -423,7 +423,7 @@ static int svc_accept(struct socket *sock, struct socket *newsock, > return error; > } > > -static int svc_getname(struct socket *sock, struct sockaddr *sockaddr, > +static int svc_getname(struct socket *sock, struct sockaddr_storage *sockaddr, > int peer) > { > struct sockaddr_atmsvc *addr; > diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c > index d6f9fae06a9d..82edd9d8a8f6 100644 > --- a/net/ax25/af_ax25.c > +++ b/net/ax25/af_ax25.c > @@ -1447,8 +1447,8 @@ static int ax25_accept(struct socket *sock, struct socket *newsock, > return err; > } > > -static int ax25_getname(struct socket *sock, struct sockaddr *uaddr, > - int peer) > +static int ax25_getname(struct socket *sock, struct sockaddr_storage *uaddr, > + int peer) > { > struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)uaddr; > struct sock *sk = sock->sk; > diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c > index 2272e1849ebd..3fe844460fc4 100644 > --- a/net/bluetooth/hci_sock.c > +++ b/net/bluetooth/hci_sock.c > @@ -1478,7 +1478,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, > return err; > } > > -static int hci_sock_getname(struct socket *sock, struct sockaddr *addr, > +static int hci_sock_getname(struct socket *sock, struct sockaddr_storage *addr, > int peer) > { > struct sockaddr_hci *haddr = (struct sockaddr_hci *)addr; > diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c > index 1b40fd2b2f02..37696247b9a8 100644 > --- a/net/bluetooth/iso.c > +++ b/net/bluetooth/iso.c > @@ -1273,15 +1273,15 @@ static int iso_sock_accept(struct socket *sock, struct socket *newsock, > return err; > } > > -static int iso_sock_getname(struct socket *sock, struct sockaddr *addr, > - int peer) > +static int iso_sock_getname(struct socket *sock, > + struct sockaddr_storage *addr, int peer) > { > struct sockaddr_iso *sa = (struct sockaddr_iso *)addr; > struct sock *sk = sock->sk; > > BT_DBG("sock %p, sk %p", sock, sk); > > - addr->sa_family = AF_BLUETOOTH; > + sa->iso_family = AF_BLUETOOTH; > > if (peer) { > bacpy(&sa->iso_bdaddr, &iso_pi(sk)->dst); > diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c > index 18e89e764f3b..799b2991ab17 100644 > --- a/net/bluetooth/l2cap_sock.c > +++ b/net/bluetooth/l2cap_sock.c > @@ -382,8 +382,8 @@ static int l2cap_sock_accept(struct socket *sock, struct socket *newsock, > return err; > } > > -static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, > - int peer) > +static int l2cap_sock_getname(struct socket *sock, > + struct sockaddr_storage *addr, int peer) > { > struct sockaddr_l2 *la = (struct sockaddr_l2 *) addr; > struct sock *sk = sock->sk; > @@ -397,7 +397,7 @@ static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, > return -ENOTCONN; > > memset(la, 0, sizeof(struct sockaddr_l2)); > - addr->sa_family = AF_BLUETOOTH; > + la->l2_family = AF_BLUETOOTH; > > la->l2_psm = chan->psm; > > diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c > index 40766f8119ed..167a95f446da 100644 > --- a/net/bluetooth/rfcomm/sock.c > +++ b/net/bluetooth/rfcomm/sock.c > @@ -529,7 +529,8 @@ static int rfcomm_sock_accept(struct socket *sock, struct socket *newsock, > return err; > } > > -static int rfcomm_sock_getname(struct socket *sock, struct sockaddr *addr, int peer) > +static int rfcomm_sock_getname(struct socket *sock, struct sockaddr_storage *addr, > + int peer) > { > struct sockaddr_rc *sa = (struct sockaddr_rc *) addr; > struct sock *sk = sock->sk; > diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c > index 78f7bca24487..a828bc2990d0 100644 > --- a/net/bluetooth/sco.c > +++ b/net/bluetooth/sco.c > @@ -750,15 +750,15 @@ static int sco_sock_accept(struct socket *sock, struct socket *newsock, > return err; > } > > -static int sco_sock_getname(struct socket *sock, struct sockaddr *addr, > - int peer) > +static int sco_sock_getname(struct socket *sock, > + struct sockaddr_storage *addr, int peer) > { > struct sockaddr_sco *sa = (struct sockaddr_sco *) addr; > struct sock *sk = sock->sk; > > BT_DBG("sock %p, sk %p", sock, sk); > > - addr->sa_family = AF_BLUETOOTH; > + sa->sco_family = AF_BLUETOOTH; > > if (peer) > bacpy(&sa->sco_bdaddr, &sco_pi(sk)->dst); > diff --git a/net/can/isotp.c b/net/can/isotp.c > index 16046931542a..5afb88885548 100644 > --- a/net/can/isotp.c > +++ b/net/can/isotp.c > @@ -1352,7 +1352,8 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len) > return err; > } > > -static int isotp_getname(struct socket *sock, struct sockaddr *uaddr, int peer) > +static int isotp_getname(struct socket *sock, struct sockaddr_storage *uaddr, > + int peer) > { > struct sockaddr_can *addr = (struct sockaddr_can *)uaddr; > struct sock *sk = sock->sk; > diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c > index 305dd72c844c..66ea829811ab 100644 > --- a/net/can/j1939/socket.c > +++ b/net/can/j1939/socket.c > @@ -598,7 +598,7 @@ static void j1939_sk_sock2sockaddr_can(struct sockaddr_can *addr, > } > } > > -static int j1939_sk_getname(struct socket *sock, struct sockaddr *uaddr, > +static int j1939_sk_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer) > { > struct sockaddr_can *addr = (struct sockaddr_can *)uaddr; > diff --git a/net/can/raw.c b/net/can/raw.c > index 255c0a8f39d6..551aec0e321e 100644 > --- a/net/can/raw.c > +++ b/net/can/raw.c > @@ -530,7 +530,7 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len) > return err; > } > > -static int raw_getname(struct socket *sock, struct sockaddr *uaddr, > +static int raw_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer) > { > struct sockaddr_can *addr = (struct sockaddr_can *)uaddr; > diff --git a/net/core/sock.c b/net/core/sock.c > index 74729d20cd00..fd6d42512530 100644 > --- a/net/core/sock.c > +++ b/net/core/sock.c > @@ -1909,7 +1909,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname, > { > struct sockaddr_storage address; > > - lv = READ_ONCE(sock->ops)->getname(sock, (struct sockaddr *)&address, 2); > + lv = READ_ONCE(sock->ops)->getname(sock, &address, 2); > if (lv < 0) > return -ENOTCONN; > if (lv < len) > @@ -3348,7 +3348,7 @@ int sock_no_accept(struct socket *sock, struct socket *newsock, > } > EXPORT_SYMBOL(sock_no_accept); > > -int sock_no_getname(struct socket *sock, struct sockaddr *saddr, > +int sock_no_getname(struct socket *sock, struct sockaddr_storage *saddr, > int peer) > { > return -EOPNOTSUPP; > diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c > index 8095e82de808..1ebe2ebe9f22 100644 > --- a/net/ipv4/af_inet.c > +++ b/net/ipv4/af_inet.c > @@ -792,7 +792,7 @@ EXPORT_SYMBOL(inet_accept); > /* > * This does both peername and sockname. > */ > -int inet_getname(struct socket *sock, struct sockaddr *uaddr, > +int inet_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer) > { > struct sock *sk = sock->sk; > diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c > index f60ec8b0f8ea..78d29dbeda1c 100644 > --- a/net/ipv6/af_inet6.c > +++ b/net/ipv6/af_inet6.c > @@ -518,7 +518,7 @@ EXPORT_SYMBOL_GPL(inet6_cleanup_sock); > /* > * This does both peername and sockname. > */ > -int inet6_getname(struct socket *sock, struct sockaddr *uaddr, > +int inet6_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer) > { > struct sockaddr_in6 *sin = (struct sockaddr_in6 *)uaddr; > diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c > index 7929df08d4e0..2612382e1a48 100644 > --- a/net/iucv/af_iucv.c > +++ b/net/iucv/af_iucv.c > @@ -848,14 +848,14 @@ static int iucv_sock_accept(struct socket *sock, struct socket *newsock, > return err; > } > > -static int iucv_sock_getname(struct socket *sock, struct sockaddr *addr, > - int peer) > +static int iucv_sock_getname(struct socket *sock, > + struct sockaddr_storage *addr, int peer) > { > DECLARE_SOCKADDR(struct sockaddr_iucv *, siucv, addr); > struct sock *sk = sock->sk; > struct iucv_sock *iucv = iucv_sk(sk); > > - addr->sa_family = AF_IUCV; > + siucv->sa_family = AF_IUCV; > > if (peer) { > memcpy(siucv->siucv_user_id, iucv->dst_user_id, 8); > diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c > index 4bc24fddfd52..ed92eabb8552 100644 > --- a/net/l2tp/l2tp_ip.c > +++ b/net/l2tp/l2tp_ip.c > @@ -373,7 +373,7 @@ static int l2tp_ip_disconnect(struct sock *sk, int flags) > return __udp_disconnect(sk, flags); > } > > -static int l2tp_ip_getname(struct socket *sock, struct sockaddr *uaddr, > +static int l2tp_ip_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer) > { > struct sock *sk = sock->sk; > diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c > index f4c1da070826..59a5e74b2561 100644 > --- a/net/l2tp/l2tp_ip6.c > +++ b/net/l2tp/l2tp_ip6.c > @@ -443,7 +443,7 @@ static int l2tp_ip6_disconnect(struct sock *sk, int flags) > return __udp_disconnect(sk, flags); > } > > -static int l2tp_ip6_getname(struct socket *sock, struct sockaddr *uaddr, > +static int l2tp_ip6_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer) > { > struct sockaddr_l2tpip6 *lsa = (struct sockaddr_l2tpip6 *)uaddr; > diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c > index 53baf2dd5d5d..ae1536ed5a5b 100644 > --- a/net/l2tp/l2tp_ppp.c > +++ b/net/l2tp/l2tp_ppp.c > @@ -886,7 +886,7 @@ static int pppol2tp_session_create(struct net *net, struct l2tp_tunnel *tunnel, > > /* getname() support. > */ > -static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr, > +static int pppol2tp_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer) > { > int len = 0; > diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c > index 0259cde394ba..12c0b14e1ef6 100644 > --- a/net/llc/af_llc.c > +++ b/net/llc/af_llc.c > @@ -1023,7 +1023,7 @@ static int llc_ui_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) > * > * Return the address information of a socket. > */ > -static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr, > +static int llc_ui_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer) > { > struct sockaddr_llc sllc; > diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c > index f4e7b5e4bb59..64ec9293136f 100644 > --- a/net/netlink/af_netlink.c > +++ b/net/netlink/af_netlink.c > @@ -1113,8 +1113,8 @@ static int netlink_connect(struct socket *sock, struct sockaddr *addr, > return err; > } > > -static int netlink_getname(struct socket *sock, struct sockaddr *addr, > - int peer) > +static int netlink_getname(struct socket *sock, > + struct sockaddr_storage *addr, int peer) > { > struct sock *sk = sock->sk; > struct netlink_sock *nlk = nlk_sk(sk); > diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c > index 6ee148f0e6d0..f845c0a56b75 100644 > --- a/net/netrom/af_netrom.c > +++ b/net/netrom/af_netrom.c > @@ -835,8 +835,8 @@ static int nr_accept(struct socket *sock, struct socket *newsock, > return err; > } > > -static int nr_getname(struct socket *sock, struct sockaddr *uaddr, > - int peer) > +static int nr_getname(struct socket *sock, struct sockaddr_storage *uaddr, > + int peer) > { > struct full_sockaddr_ax25 *sax = (struct full_sockaddr_ax25 *)uaddr; > struct sock *sk = sock->sk; > diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c > index 57a2f97004e1..1ba19e542320 100644 > --- a/net/nfc/llcp_sock.c > +++ b/net/nfc/llcp_sock.c > @@ -500,8 +500,8 @@ static int llcp_sock_accept(struct socket *sock, struct socket *newsock, > return ret; > } > > -static int llcp_sock_getname(struct socket *sock, struct sockaddr *uaddr, > - int peer) > +static int llcp_sock_getname(struct socket *sock, > + struct sockaddr_storage *uaddr, int peer) > { > struct sock *sk = sock->sk; > struct nfc_llcp_sock *llcp_sock = nfc_llcp_sock(sk); > diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c > index 886c0dd47b66..3661476920af 100644 > --- a/net/packet/af_packet.c > +++ b/net/packet/af_packet.c > @@ -3640,27 +3640,28 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, > return err; > } > > -static int packet_getname_spkt(struct socket *sock, struct sockaddr *uaddr, > - int peer) > +static int packet_getname_spkt(struct socket *sock, > + struct sockaddr_storage *uaddr, int peer) > { > + struct sockaddr *addr = (struct sockaddr *)uaddr; > struct net_device *dev; > struct sock *sk = sock->sk; > > if (peer) > return -EOPNOTSUPP; > > - uaddr->sa_family = AF_PACKET; > - memset(uaddr->sa_data, 0, sizeof(uaddr->sa_data_min)); > + addr->sa_family = AF_PACKET; > + memset(addr->sa_data, 0, sizeof(addr->sa_data_min)); > rcu_read_lock(); > dev = dev_get_by_index_rcu(sock_net(sk), READ_ONCE(pkt_sk(sk)->ifindex)); > if (dev) > - strscpy(uaddr->sa_data, dev->name, sizeof(uaddr->sa_data_min)); > + strscpy(addr->sa_data, dev->name, sizeof(addr->sa_data_min)); > rcu_read_unlock(); > > - return sizeof(*uaddr); > + return sizeof(*addr); > } > > -static int packet_getname(struct socket *sock, struct sockaddr *uaddr, > +static int packet_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer) > { > struct net_device *dev; > diff --git a/net/phonet/socket.c b/net/phonet/socket.c > index 5ce0b3ee5def..711c70cc110a 100644 > --- a/net/phonet/socket.c > +++ b/net/phonet/socket.c > @@ -311,17 +311,17 @@ static int pn_socket_accept(struct socket *sock, struct socket *newsock, > return 0; > } > > -static int pn_socket_getname(struct socket *sock, struct sockaddr *addr, > - int peer) > +static int pn_socket_getname(struct socket *sock, > + struct sockaddr_storage *uaddr, int peer) > { > + struct sockaddr_pn *addr = (struct sockaddr_pn *)uaddr; > struct sock *sk = sock->sk; > struct pn_sock *pn = pn_sk(sk); > > memset(addr, 0, sizeof(struct sockaddr_pn)); > - addr->sa_family = AF_PHONET; > + addr->spn_family = AF_PHONET; > if (!peer) /* Race with bind() here is userland's problem. */ > - pn_sockaddr_set_object((struct sockaddr_pn *)addr, > - pn->sobject); > + pn_sockaddr_set_object(addr, pn->sobject); > > return sizeof(struct sockaddr_pn); > } > diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c > index 00c51cf693f3..836c9a4a2119 100644 > --- a/net/qrtr/af_qrtr.c > +++ b/net/qrtr/af_qrtr.c > @@ -1115,7 +1115,7 @@ static int qrtr_connect(struct socket *sock, struct sockaddr *saddr, > return 0; > } > > -static int qrtr_getname(struct socket *sock, struct sockaddr *saddr, > +static int qrtr_getname(struct socket *sock, struct sockaddr_storage *saddr, > int peer) > { > struct qrtr_sock *ipc = qrtr_sk(sock->sk); > diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c > index 3de9350cbf30..0409983eb9fb 100644 > --- a/net/qrtr/ns.c > +++ b/net/qrtr/ns.c > @@ -697,7 +697,7 @@ int qrtr_ns_init(void) > if (ret < 0) > return ret; > > - ret = kernel_getsockname(qrtr_ns.sock, (struct sockaddr *)&sq); > + ret = kernel_getsockname(qrtr_ns.sock, (struct sockaddr_storage *)&sq); > if (ret < 0) { > pr_err("failed to get socket name\n"); > goto err_sock; > diff --git a/net/rds/af_rds.c b/net/rds/af_rds.c > index 8435a20968ef..6d0cef028454 100644 > --- a/net/rds/af_rds.c > +++ b/net/rds/af_rds.c > @@ -111,7 +111,7 @@ void rds_wake_sk_sleep(struct rds_sock *rs) > read_unlock_irqrestore(&rs->rs_recv_lock, flags); > } > > -static int rds_getname(struct socket *sock, struct sockaddr *uaddr, > +static int rds_getname(struct socket *sock, struct sockaddr_storage *uaddr, I missed this small rds change here earlier. This change looks fine to me. Thanks Kees! Sorry for the delay! Acked-by: Allison Henderson Allison > int peer) > { > struct rds_sock *rs = rds_sk_to_rs(sock->sk); > diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c > index 59050caab65c..0260a5862cf7 100644 > --- a/net/rose/af_rose.c > +++ b/net/rose/af_rose.c > @@ -984,8 +984,8 @@ static int rose_accept(struct socket *sock, struct socket *newsock, > return err; > } > > -static int rose_getname(struct socket *sock, struct sockaddr *uaddr, > - int peer) > +static int rose_getname(struct socket *sock, struct sockaddr_storage *uaddr, > + int peer) > { > struct full_sockaddr_rose *srose = (struct full_sockaddr_rose *)uaddr; > struct sock *sk = sock->sk; > diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c > index a9ed2ccab1bd..2d8decaae609 100644 > --- a/net/sctp/ipv6.c > +++ b/net/sctp/ipv6.c > @@ -1065,7 +1065,7 @@ static int sctp_inet6_supported_addrs(const struct sctp_sock *opt, > } > > /* Handle SCTP_I_WANT_MAPPED_V4_ADDR for getpeername() and getsockname() */ > -static int sctp_getname(struct socket *sock, struct sockaddr *uaddr, > +static int sctp_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer) > { > int rc; > diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c > index 9e6c69d18581..5d44d2392268 100644 > --- a/net/smc/af_smc.c > +++ b/net/smc/af_smc.c > @@ -2741,7 +2741,7 @@ int smc_accept(struct socket *sock, struct socket *new_sock, > return rc; > } > > -int smc_getname(struct socket *sock, struct sockaddr *addr, > +int smc_getname(struct socket *sock, struct sockaddr_storage *addr, > int peer) > { > struct smc_sock *smc; > diff --git a/net/smc/smc.h b/net/smc/smc.h > index 78ae10d06ed2..24260f4e6830 100644 > --- a/net/smc/smc.h > +++ b/net/smc/smc.h > @@ -48,7 +48,7 @@ int smc_connect(struct socket *sock, struct sockaddr *addr, > int alen, int flags); > int smc_accept(struct socket *sock, struct socket *new_sock, > struct proto_accept_arg *arg); > -int smc_getname(struct socket *sock, struct sockaddr *addr, > +int smc_getname(struct socket *sock, struct sockaddr_storage *addr, > int peer); > __poll_t smc_poll(struct file *file, struct socket *sock, > poll_table *wait); > diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c > index 33fa787c28eb..6eeb5decc51e 100644 > --- a/net/smc/smc_clc.c > +++ b/net/smc/smc_clc.c > @@ -571,7 +571,7 @@ static int smc_clc_prfx_set(struct socket *clcsock, > goto out_rel; > } > /* get address to which the internal TCP socket is bound */ > - if (kernel_getsockname(clcsock, (struct sockaddr *)&addrs) < 0) > + if (kernel_getsockname(clcsock, &addrs) < 0) > goto out_rel; > /* analyze IP specific data of net_device belonging to TCP socket */ > addr6 = (struct sockaddr_in6 *)&addrs; > diff --git a/net/socket.c b/net/socket.c > index 9a117248f18f..b10f2b3f4054 100644 > --- a/net/socket.c > +++ b/net/socket.c > @@ -1943,7 +1943,7 @@ struct file *do_accept(struct file *file, struct proto_accept_arg *arg, > goto out_fd; > > if (upeer_sockaddr) { > - len = ops->getname(newsock, (struct sockaddr *)&address, 2); > + len = ops->getname(newsock, &address, 2); > if (len < 0) { > err = -ECONNABORTED; > goto out_fd; > @@ -2103,7 +2103,7 @@ int __sys_getsockname(int fd, struct sockaddr __user *usockaddr, > if (err) > return err; > > - err = READ_ONCE(sock->ops)->getname(sock, (struct sockaddr *)&address, 0); > + err = READ_ONCE(sock->ops)->getname(sock, &address, 0); > if (err < 0) > return err; > > @@ -2140,7 +2140,7 @@ int __sys_getpeername(int fd, struct sockaddr __user *usockaddr, > if (err) > return err; > > - err = READ_ONCE(sock->ops)->getname(sock, (struct sockaddr *)&address, 1); > + err = READ_ONCE(sock->ops)->getname(sock, &address, 1); > if (err < 0) > return err; > > @@ -3636,7 +3636,7 @@ EXPORT_SYMBOL(kernel_connect); > * Returns the length of the address in bytes or an error code. > */ > > -int kernel_getsockname(struct socket *sock, struct sockaddr *addr) > +int kernel_getsockname(struct socket *sock, struct sockaddr_storage *addr) > { > return READ_ONCE(sock->ops)->getname(sock, addr, 0); > } > @@ -3651,7 +3651,7 @@ EXPORT_SYMBOL(kernel_getsockname); > * Returns the length of the address in bytes or an error code. > */ > > -int kernel_getpeername(struct socket *sock, struct sockaddr *addr) > +int kernel_getpeername(struct socket *sock, struct sockaddr_storage *addr) > { > return READ_ONCE(sock->ops)->getname(sock, addr, 1); > } > diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c > index 0090162ee8c3..8af253f5ad08 100644 > --- a/net/sunrpc/clnt.c > +++ b/net/sunrpc/clnt.c > @@ -1445,7 +1445,7 @@ static const struct sockaddr_in6 rpc_in6addr_loopback = { > * negative errno is returned. > */ > static int rpc_sockname(struct net *net, struct sockaddr *sap, size_t salen, > - struct sockaddr *buf) > + struct sockaddr_storage *buf) > { > struct socket *sock; > int err; > @@ -1490,7 +1490,7 @@ static int rpc_sockname(struct net *net, struct sockaddr *sap, size_t salen, > } > > err = 0; > - if (buf->sa_family == AF_INET6) { > + if (buf->ss_family == AF_INET6) { > struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)buf; > sin6->sin6_scope_id = 0; > } > @@ -1510,7 +1510,7 @@ static int rpc_sockname(struct net *net, struct sockaddr *sap, size_t salen, > * Returns zero and fills in "buf" if successful; otherwise, a > * negative errno is returned. > */ > -static int rpc_anyaddr(int family, struct sockaddr *buf, size_t buflen) > +static int rpc_anyaddr(int family, struct sockaddr_storage *buf, size_t buflen) > { > switch (family) { > case AF_INET: > @@ -1550,7 +1550,8 @@ static int rpc_anyaddr(int family, struct sockaddr *buf, size_t buflen) > * succession may give different results, depending on how local > * networking configuration changes over time. > */ > -int rpc_localaddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t buflen) > +int rpc_localaddr(struct rpc_clnt *clnt, struct sockaddr_storage *buf, > + size_t buflen) > { > struct sockaddr_storage address; > struct sockaddr *sap = (struct sockaddr *)&address; > diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c > index 95397677673b..b062fadb2e6b 100644 > --- a/net/sunrpc/svcsock.c > +++ b/net/sunrpc/svcsock.c > @@ -903,7 +903,7 @@ static struct svc_xprt *svc_tcp_accept(struct svc_xprt *xprt) > > set_bit(XPT_CONN, &svsk->sk_xprt.xpt_flags); > > - err = kernel_getpeername(newsock, sin); > + err = kernel_getpeername(newsock, &addr); > if (err < 0) { > trace_svcsock_getpeername_err(xprt, serv->sv_name, err); > goto failed; /* aborted connection or whatever */ > @@ -925,7 +925,7 @@ static struct svc_xprt *svc_tcp_accept(struct svc_xprt *xprt) > if (IS_ERR(newsvsk)) > goto failed; > svc_xprt_set_remote(&newsvsk->sk_xprt, sin, slen); > - err = kernel_getsockname(newsock, sin); > + err = kernel_getsockname(newsock, &addr); > slen = err; > if (unlikely(err < 0)) > slen = offsetof(struct sockaddr, sa_data); > @@ -1478,7 +1478,7 @@ int svc_addsock(struct svc_serv *serv, struct net *net, const int fd, > err = PTR_ERR(svsk); > goto out; > } > - salen = kernel_getsockname(svsk->sk_sock, sin); > + salen = kernel_getsockname(svsk->sk_sock, &addr); > if (salen >= 0) > svc_xprt_set_local(&svsk->sk_xprt, sin, salen); > svsk->sk_xprt.xpt_cred = get_cred(cred); > @@ -1545,7 +1545,7 @@ static struct svc_xprt *svc_create_socket(struct svc_serv *serv, > if (error < 0) > goto bummer; > > - error = kernel_getsockname(sock, newsin); > + error = kernel_getsockname(sock, &addr); > if (error < 0) > goto bummer; > newlen = error; > diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c > index c60936d8cef7..735c3c1d2bdf 100644 > --- a/net/sunrpc/xprtsock.c > +++ b/net/sunrpc/xprtsock.c > @@ -1710,7 +1710,7 @@ static unsigned short xs_sock_getport(struct socket *sock) > struct sockaddr_storage buf; > unsigned short port = 0; > > - if (kernel_getsockname(sock, (struct sockaddr *)&buf) < 0) > + if (kernel_getsockname(sock, &buf) < 0) > goto out; > switch (buf.ss_family) { > case AF_INET6: > @@ -1779,7 +1779,7 @@ static int xs_sock_srcaddr(struct rpc_xprt *xprt, char *buf, size_t buflen) > > mutex_lock(&sock->recv_mutex); > if (sock->sock) { > - ret = kernel_getsockname(sock->sock, &saddr.sa); > + ret = kernel_getsockname(sock->sock, &saddr.st); > if (ret >= 0) > ret = snprintf(buf, buflen, "%pISc", &saddr.sa); > } > diff --git a/net/tipc/socket.c b/net/tipc/socket.c > index 65dcbb54f55d..56f609c7f2a6 100644 > --- a/net/tipc/socket.c > +++ b/net/tipc/socket.c > @@ -741,7 +741,7 @@ static int tipc_bind(struct socket *sock, struct sockaddr *skaddr, int alen) > * accesses socket information that is unchanging (or which changes in > * a completely predictable manner). > */ > -static int tipc_getname(struct socket *sock, struct sockaddr *uaddr, > +static int tipc_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer) > { > struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; > diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c > index 001ccc55ef0f..0f71ed2f35e7 100644 > --- a/net/unix/af_unix.c > +++ b/net/unix/af_unix.c > @@ -813,7 +813,7 @@ static int unix_stream_connect(struct socket *, struct sockaddr *, > int addr_len, int flags); > static int unix_socketpair(struct socket *, struct socket *); > static int unix_accept(struct socket *, struct socket *, struct proto_accept_arg *arg); > -static int unix_getname(struct socket *, struct sockaddr *, int); > +static int unix_getname(struct socket *, struct sockaddr_storage *, int); > static __poll_t unix_poll(struct file *, struct socket *, poll_table *); > static __poll_t unix_dgram_poll(struct file *, struct socket *, > poll_table *); > @@ -1789,7 +1789,8 @@ static int unix_accept(struct socket *sock, struct socket *newsock, > } > > > -static int unix_getname(struct socket *sock, struct sockaddr *uaddr, int peer) > +static int unix_getname(struct socket *sock, struct sockaddr_storage *uaddr, > + int peer) > { > struct sock *sk = sock->sk; > struct unix_address *addr; > @@ -1817,10 +1818,10 @@ static int unix_getname(struct socket *sock, struct sockaddr *uaddr, int peer) > memcpy(sunaddr, addr->name, addr->len); > > if (peer) > - BPF_CGROUP_RUN_SA_PROG(sk, uaddr, &err, > + BPF_CGROUP_RUN_SA_PROG(sk, (struct sockaddr *)uaddr, &err, > CGROUP_UNIX_GETPEERNAME); > else > - BPF_CGROUP_RUN_SA_PROG(sk, uaddr, &err, > + BPF_CGROUP_RUN_SA_PROG(sk, (struct sockaddr *)uaddr, &err, > CGROUP_UNIX_GETSOCKNAME); > } > sock_put(sk); > diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c > index 5cf8109f672a..6b51ee9cb8d3 100644 > --- a/net/vmw_vsock/af_vsock.c > +++ b/net/vmw_vsock/af_vsock.c > @@ -943,7 +943,7 @@ vsock_bind(struct socket *sock, struct sockaddr *addr, int addr_len) > } > > static int vsock_getname(struct socket *sock, > - struct sockaddr *addr, int peer) > + struct sockaddr_storage *addr, int peer) > { > int err; > struct sock *sk; > diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c > index 8dda4178497c..f97876d30935 100644 > --- a/net/x25/af_x25.c > +++ b/net/x25/af_x25.c > @@ -913,7 +913,7 @@ static int x25_accept(struct socket *sock, struct socket *newsock, > return rc; > } > > -static int x25_getname(struct socket *sock, struct sockaddr *uaddr, > +static int x25_getname(struct socket *sock, struct sockaddr_storage *uaddr, > int peer) > { > struct sockaddr_x25 *sx25 = (struct sockaddr_x25 *)uaddr; > diff --git a/security/tomoyo/network.c b/security/tomoyo/network.c > index 8dc61335f65e..450fd7a37ca4 100644 > --- a/security/tomoyo/network.c > +++ b/security/tomoyo/network.c > @@ -658,8 +658,7 @@ int tomoyo_socket_listen_permission(struct socket *sock) > if (!family || (type != SOCK_STREAM && type != SOCK_SEQPACKET)) > return 0; > { > - const int error = sock->ops->getname(sock, (struct sockaddr *) > - &addr, 0); > + const int error = sock->ops->getname(sock, &addr, 0); > > if (error < 0) > return error; From mkl at pengutronix.de Thu Jan 16 07:53:42 2025 From: mkl at pengutronix.de (Marc Kleine-Budde) Date: Thu, 16 Jan 2025 08:53:42 +0100 Subject: [rds-devel] [PATCH] net: Convert proto_ops::getname to sockaddr_storage In-Reply-To: <20241217023417.work.145-kees@kernel.org> References: <20241217023417.work.145-kees@kernel.org> Message-ID: <20250116-light-panda-of-reverence-2f5da8-mkl@pengutronix.de> On 16.12.2024 18:34:28, Kees Cook wrote: > The proto_ops::getname callback was long ago backed by sockaddr_storage, > but the replacement of it for sockaddr was never done. Plumb it through > all the getname() callbacks, adjust prototypes, and fix casts. > > There are a few cases where the backing object is _not_ a sockaddr_storage > and converting it looks painful. In those cases, they use a cast to > struct sockaddr_storage. They appear well bounds-checked, so the risk > is no worse that we have currently. > > Other casts to sockaddr are removed, though to avoid spilling this > change into BPF (which becomes a much larger set of changes), cast the > sockaddr_storage instances there to sockaddr for the time being. > > In theory this could be split up into per-caller patches that add more > casts that all later get removed, but it seemed like there are few > enough callers that it seems feasible to do this in a single patch. Most > conversions are mechanical, so review should be fairly easy. (Famous > last words.) > > Signed-off-by: Kees Cook > --- > net/can/isotp.c | 3 +- > net/can/j1939/socket.c | 2 +- > net/can/raw.c | 2 +- Acked-by: Marc Kleine-Budde # for net/can regards, Marc -- Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung N?rnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: not available URL: