net/smc: fixes 2018-02-28
cover net/smc: fixes 2018-02-28
Dave,
here are 3 smc bug fixes for the net-tree. Karsten's first patch is the reworked version of last week's
"[PATCH net-next 2/5] net/smc: fix structure size"
patch, now solved without using __packed, and now targetted for net instead of net-next.
Thanks, Ursula
Davide Caratti (1):
net/smc: fix NULL pointer dereference on sock_create_kern() error path
Karsten Graul (2):
net/smc: use a constant for control message length net/smc: use link_id of server in confirm link reply
net/smc/af_smc.c | 4 +++- net/smc/smc_cdc.c | 2 +- net/smc/smc_core.c | 3 ++- net/smc/smc_llc.c | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
2.13.5
PATCH 1/3 net/smc: use a constant for control message length
From: Karsten Graul <[email protected]>
The sizeof(struct smc_cdc_msg) evaluates to 48 bytes instead of the required 44 bytes. We need to use the constant value of SMC_WR_TX_SIZE to set and check the control message length.
--- net/smc/smc_cdc.c | 2 +- net/smc/smc_core.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/smc/smc_cdc.c +1 -1
@@ -269,7 +269,7 @@ static void smc_cdc_rx_handler(struct ib_wc *wc, void *buf)if (wc->byte_len < offsetof(struct smc_cdc_msg , reserved))return ;/* short message */ -if (cdc->len !=sizeof (*cdc)) +if (cdc->len !=SMC_WR_TX_SIZE )return ;/* invalid message */ smc_cdc_msg_recv (cdc, link, wc->wr_id); }
net/smc/smc_core.c +1 -1
@@ -465,7 +465,7 @@ int smc_conn_create(struct smc_sock *smc, __be32 peer_in_addr, rc =smc_link_determine_gid (conn->lgr); } conn->local_tx_ctrl.common.type =SMC_CDC_MSG_TYPE ; - conn->local_tx_ctrl.len =sizeof (struct smc_cdc_msg ); + conn->local_tx_ctrl.len =SMC_WR_TX_SIZE ;#ifndef KERNEL_HAS_ATOMIC64 spin_lock_init (&conn->acurs_lock);#endif
Signature · 1 line
2.13.5
PATCH 2/3 net/smc: use link_id of server in confirm link reply
In reply to Ursula BraunFrom: Karsten Graul <[email protected]>
The CONFIRM LINK reply message must contain the link_id sent by the server. And set the link_id explicitly when initializing the link.
--- net/smc/smc_core.c | 1 + net/smc/smc_llc.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
net/smc/smc_core.c +1 -0
@@ -177,6 +177,7 @@ static int smc_lgr_create(struct smc_sock *smc, __be32 peer_in_addr, lnk = &lgr->lnk[SMC_SINGLE_LINK ];/* initialize link */ + lnk->link_id =SMC_SINGLE_LINK ; lnk->smcibdev = smcibdev; lnk->ibport = ibport; lnk->path_mtu = smcibdev->pattr[ibport -1 ].active_mtu;
net/smc/smc_llc.c +1 -1
@@ -92,7 +92,7 @@ int smc_llc_send_confirm_link(struct smc_link *link, u8 mac[],memcpy (confllc->sender_mac, mac,ETH_ALEN );memcpy (confllc->sender_gid, gid,SMC_GID_SIZE );hton24 (confllc->sender_qp_num, link->roce_qp->qp_num); -/* confllc->link_num = SMC_SINGLE_LINK; already done by memset above */ + confllc->link_num = link->link_id;memcpy (confllc->link_uid, lgr->id,SMC_LGR_ID_SIZE ); confllc->max_links =SMC_LINKS_PER_LGR_MAX ;/* send llc message */
Signature · 1 line
2.13.5
PATCH 3/3 net/smc: fix NULL pointer dereference on sock_create_kern() error path
In reply to Ursula BraunFrom: Davide Caratti <[email protected]>
when sock_create_kern(..., a) returns an error, 'a' might not be a valid pointer, so it shouldn't be dereferenced to read a->sk->sk_sndbuf and and a->sk->sk_rcvbuf; not doing that caused the following crash:
general protection fault: 0000 [#1] SMP KASAN
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in:
CPU: 0 PID: 4254 Comm: syzkaller919713 Not tainted 4.16.0-rc1+ #18
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
RIP: 0010:smc_create+0x14e/0x300 net/smc/af_smc.c:1410
RSP: 0018:ffff8801b06afbc8 EFLAGS: 00010202
RAX: dffffc0000000000 RBX: ffff8801b63457c0 RCX: ffffffff85a3e746
RDX: 0000000000000004 RSI: 00000000ffffffff RDI: 0000000000000020
RBP: ffff8801b06afbf0 R08: 00000000000007c0 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
R13: ffff8801b6345c08 R14: 00000000ffffffe9 R15: ffffffff8695ced0
FS: 0000000001afb880(0000) GS:ffff8801db200000(0000)
knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000020000040 CR3: 00000001b0721004 CR4: 00000000001606f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
__sock_create+0x4d4/0x850 net/socket.c:1285
sock_create net/socket.c:1325 [inline]
SYSC_socketpair net/socket.c:1409 [inline]
SyS_socketpair+0x1c0/0x6f0 net/socket.c:1366
do_syscall_64+0x282/0x940 arch/x86/entry/common.c:287
entry_SYSCALL_64_after_hwframe+0x26/0x9b
RIP: 0033:0x4404b9
RSP: 002b:00007fff44ab6908 EFLAGS: 00000246 ORIG_RAX: 0000000000000035
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00000000004404b9
RDX: 0000000000000000 RSI: 0000000000000001 RDI: 000000000000002b
RBP: 00007fff44ab6910 R08: 0000000000000002 R09: 00007fff44003031
R10: 0000000020000040 R11: 0000000000000246 R12: ffffffffffffffff
R13: 0000000000000006 R14: 0000000000000000 R15: 0000000000000000
Code: 48 c1 ea 03 80 3c 02 00 0f 85 b3 01 00 00 4c 8b a3 48 04 00 00 48b8
00 00 00 00 00 fc ff df 49 8d 7c 24 20 48 89 fa 48 c1 ea 03 <80> 3c 02 00
0f 85 82 01 00 00 4d 8b 7c 24 20 48 b8 00 00 00 00
RIP: smc_create+0x14e/0x300 net/smc/af_smc.c:1410 RSP: ffff8801b06afbc8
--- net/smc/af_smc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/smc/af_smc.c +3 -1
@@ -1406,8 +1406,10 @@ static int smc_create(struct net *net, struct socket *sock, int protocol, smc->use_fallback = false;/* assume rdma capability first */ rc =sock_create_kern (net,PF_INET ,SOCK_STREAM ,IPPROTO_TCP , &smc->clcsock); -if (rc) +if (rc) {sk_common_release (sk); + goto out; + } smc->sk.sk_sndbuf =max (smc->clcsock->sk->sk_sndbuf,SMC_BUF_MIN_SIZE ); smc->sk.sk_rcvbuf =max (smc->clcsock->sk->sk_rcvbuf,SMC_BUF_MIN_SIZE );
Signature · 1 line
2.13.5
David Miller
maintainerFrom: Ursula Braun <[email protected]>
Date: Wed, 28 Feb 2018 12:44:06 +0100
Quoted 5 lines
here are 3 smc bug fixes for the net-tree. Karsten's first patch is the reworked version of last week's
"[PATCH net-next 2/5] net/smc: fix structure size"
patch, now solved without using__packed, and now targetted for net instead of net-next.
Series applied, thank you.