From: Sasha Levin Date: Sun, 23 May 2021 20:05:32 +0000 (-0400) Subject: Fixes for 4.9 X-Git-Tag: v4.4.270~71 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5ed571619bacc3bb0bd4c171ad3637da8f02dde7;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 4.9 Signed-off-by: Sasha Levin --- diff --git a/queue-4.9/openrisc-fix-a-memory-leak.patch b/queue-4.9/openrisc-fix-a-memory-leak.patch new file mode 100644 index 00000000000..dc7f3716392 --- /dev/null +++ b/queue-4.9/openrisc-fix-a-memory-leak.patch @@ -0,0 +1,42 @@ +From ff4ca3227dfca6d0b2e8d6934ce1c888581ba579 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 23 Apr 2021 17:09:28 +0200 +Subject: openrisc: Fix a memory leak + +From: Christophe JAILLET + +[ Upstream commit c019d92457826bb7b2091c86f36adb5de08405f9 ] + +'setup_find_cpu_node()' take a reference on the node it returns. +This reference must be decremented when not needed anymore, or there will +be a leak. + +Add the missing 'of_node_put(cpu)'. + +Note that 'setup_cpuinfo()' that also calls this function already has a +correct 'of_node_put(cpu)' at its end. + +Fixes: 9d02a4283e9c ("OpenRISC: Boot code") +Signed-off-by: Christophe JAILLET +Signed-off-by: Stafford Horne +Signed-off-by: Sasha Levin +--- + arch/openrisc/kernel/setup.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/arch/openrisc/kernel/setup.c b/arch/openrisc/kernel/setup.c +index b4ed8b36e078..e5f5b69a7b7b 100644 +--- a/arch/openrisc/kernel/setup.c ++++ b/arch/openrisc/kernel/setup.c +@@ -278,6 +278,8 @@ void calibrate_delay(void) + pr_cont("%lu.%02lu BogoMIPS (lpj=%lu)\n", + loops_per_jiffy / (500000 / HZ), + (loops_per_jiffy / (5000 / HZ)) % 100, loops_per_jiffy); ++ ++ of_node_put(cpu); + } + + void __init setup_arch(char **cmdline_p) +-- +2.30.2 + diff --git a/queue-4.9/ptrace-make-ptrace-fail-if-the-tracee-changed-its-pi.patch b/queue-4.9/ptrace-make-ptrace-fail-if-the-tracee-changed-its-pi.patch new file mode 100644 index 00000000000..bb18463b76e --- /dev/null +++ b/queue-4.9/ptrace-make-ptrace-fail-if-the-tracee-changed-its-pi.patch @@ -0,0 +1,161 @@ +From 9cc2c57c52af98c903f75165faa0005a10b8d9af Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 12 May 2021 15:33:08 +0200 +Subject: ptrace: make ptrace() fail if the tracee changed its pid unexpectedly + +From: Oleg Nesterov + +[ Upstream commit dbb5afad100a828c97e012c6106566d99f041db6 ] + +Suppose we have 2 threads, the group-leader L and a sub-theread T, +both parked in ptrace_stop(). Debugger tries to resume both threads +and does + + ptrace(PTRACE_CONT, T); + ptrace(PTRACE_CONT, L); + +If the sub-thread T execs in between, the 2nd PTRACE_CONT doesn not +resume the old leader L, it resumes the post-exec thread T which was +actually now stopped in PTHREAD_EVENT_EXEC. In this case the +PTHREAD_EVENT_EXEC event is lost, and the tracer can't know that the +tracee changed its pid. + +This patch makes ptrace() fail in this case until debugger does wait() +and consumes PTHREAD_EVENT_EXEC which reports old_pid. This affects all +ptrace requests except the "asynchronous" PTRACE_INTERRUPT/KILL. + +The patch doesn't add the new PTRACE_ option to not complicate the API, +and I _hope_ this won't cause any noticeable regression: + + - If debugger uses PTRACE_O_TRACEEXEC and the thread did an exec + and the tracer does a ptrace request without having consumed + the exec event, it's 100% sure that the thread the ptracer + thinks it is targeting does not exist anymore, or isn't the + same as the one it thinks it is targeting. + + - To some degree this patch adds nothing new. In the scenario + above ptrace(L) can fail with -ESRCH if it is called after the + execing sub-thread wakes the leader up and before it "steals" + the leader's pid. + +Test-case: + + #include + #include + #include + #include + #include + #include + #include + #include + + void *tf(void *arg) + { + execve("/usr/bin/true", NULL, NULL); + assert(0); + + return NULL; + } + + int main(void) + { + int leader = fork(); + if (!leader) { + kill(getpid(), SIGSTOP); + + pthread_t th; + pthread_create(&th, NULL, tf, NULL); + for (;;) + pause(); + + return 0; + } + + waitpid(leader, NULL, WSTOPPED); + + ptrace(PTRACE_SEIZE, leader, 0, + PTRACE_O_TRACECLONE | PTRACE_O_TRACEEXEC); + waitpid(leader, NULL, 0); + + ptrace(PTRACE_CONT, leader, 0,0); + waitpid(leader, NULL, 0); + + int status, thread = waitpid(-1, &status, 0); + assert(thread > 0 && thread != leader); + assert(status == 0x80137f); + + ptrace(PTRACE_CONT, thread, 0,0); + /* + * waitid() because waitpid(leader, &status, WNOWAIT) does not + * report status. Why ???? + * + * Why WEXITED? because we have another kernel problem connected + * to mt-exec. + */ + siginfo_t info; + assert(waitid(P_PID, leader, &info, WSTOPPED|WEXITED|WNOWAIT) == 0); + assert(info.si_pid == leader && info.si_status == 0x0405); + + /* OK, it sleeps in ptrace(PTRACE_EVENT_EXEC == 0x04) */ + assert(ptrace(PTRACE_CONT, leader, 0,0) == -1); + assert(errno == ESRCH); + + assert(leader == waitpid(leader, &status, WNOHANG)); + assert(status == 0x04057f); + + assert(ptrace(PTRACE_CONT, leader, 0,0) == 0); + + return 0; + } + +Signed-off-by: Oleg Nesterov +Reported-by: Simon Marchi +Acked-by: "Eric W. Biederman" +Acked-by: Pedro Alves +Acked-by: Simon Marchi +Acked-by: Jan Kratochvil +Signed-off-by: Linus Torvalds +Signed-off-by: Sasha Levin +--- + kernel/ptrace.c | 18 +++++++++++++++++- + 1 file changed, 17 insertions(+), 1 deletion(-) + +diff --git a/kernel/ptrace.c b/kernel/ptrace.c +index ea3370e205fb..4f10223bc7b0 100644 +--- a/kernel/ptrace.c ++++ b/kernel/ptrace.c +@@ -159,6 +159,21 @@ void __ptrace_unlink(struct task_struct *child) + spin_unlock(&child->sighand->siglock); + } + ++static bool looks_like_a_spurious_pid(struct task_struct *task) ++{ ++ if (task->exit_code != ((PTRACE_EVENT_EXEC << 8) | SIGTRAP)) ++ return false; ++ ++ if (task_pid_vnr(task) == task->ptrace_message) ++ return false; ++ /* ++ * The tracee changed its pid but the PTRACE_EVENT_EXEC event ++ * was not wait()'ed, most probably debugger targets the old ++ * leader which was destroyed in de_thread(). ++ */ ++ return true; ++} ++ + /* Ensure that nothing can wake it up, even SIGKILL */ + static bool ptrace_freeze_traced(struct task_struct *task) + { +@@ -169,7 +184,8 @@ static bool ptrace_freeze_traced(struct task_struct *task) + return ret; + + spin_lock_irq(&task->sighand->siglock); +- if (task_is_traced(task) && !__fatal_signal_pending(task)) { ++ if (task_is_traced(task) && !looks_like_a_spurious_pid(task) && ++ !__fatal_signal_pending(task)) { + task->state = __TASK_TRACED; + ret = true; + } +-- +2.30.2 + diff --git a/queue-4.9/rdma-rxe-clear-all-qp-fields-if-creation-failed.patch b/queue-4.9/rdma-rxe-clear-all-qp-fields-if-creation-failed.patch new file mode 100644 index 00000000000..612dcc88806 --- /dev/null +++ b/queue-4.9/rdma-rxe-clear-all-qp-fields-if-creation-failed.patch @@ -0,0 +1,117 @@ +From 60b12b0f24727e2121f09f0c0afec44c8c9695a1 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 11 May 2021 10:26:03 +0300 +Subject: RDMA/rxe: Clear all QP fields if creation failed + +From: Leon Romanovsky + +[ Upstream commit 67f29896fdc83298eed5a6576ff8f9873f709228 ] + +rxe_qp_do_cleanup() relies on valid pointer values in QP for the properly +created ones, but in case rxe_qp_from_init() failed it was filled with +garbage and caused tot the following error. + + refcount_t: underflow; use-after-free. + WARNING: CPU: 1 PID: 12560 at lib/refcount.c:28 refcount_warn_saturate+0x1d1/0x1e0 lib/refcount.c:28 + Modules linked in: + CPU: 1 PID: 12560 Comm: syz-executor.4 Not tainted 5.12.0-syzkaller #0 + Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 + RIP: 0010:refcount_warn_saturate+0x1d1/0x1e0 lib/refcount.c:28 + Code: e9 db fe ff ff 48 89 df e8 2c c2 ea fd e9 8a fe ff ff e8 72 6a a7 fd 48 c7 c7 e0 b2 c1 89 c6 05 dc 3a e6 09 01 e8 ee 74 fb 04 <0f> 0b e9 af fe ff ff 0f 1f 84 00 00 00 00 00 41 56 41 55 41 54 55 + RSP: 0018:ffffc900097ceba8 EFLAGS: 00010286 + RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000 + RDX: 0000000000040000 RSI: ffffffff815bb075 RDI: fffff520012f9d67 + RBP: 0000000000000003 R08: 0000000000000000 R09: 0000000000000000 + R10: ffffffff815b4eae R11: 0000000000000000 R12: ffff8880322a4800 + R13: ffff8880322a4940 R14: ffff888033044e00 R15: 0000000000000000 + FS: 00007f6eb2be3700(0000) GS:ffff8880b9d00000(0000) knlGS:0000000000000000 + CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 + CR2: 00007fdbe5d41000 CR3: 000000001d181000 CR4: 00000000001506e0 + DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 + DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 + Call Trace: + __refcount_sub_and_test include/linux/refcount.h:283 [inline] + __refcount_dec_and_test include/linux/refcount.h:315 [inline] + refcount_dec_and_test include/linux/refcount.h:333 [inline] + kref_put include/linux/kref.h:64 [inline] + rxe_qp_do_cleanup+0x96f/0xaf0 drivers/infiniband/sw/rxe/rxe_qp.c:805 + execute_in_process_context+0x37/0x150 kernel/workqueue.c:3327 + rxe_elem_release+0x9f/0x180 drivers/infiniband/sw/rxe/rxe_pool.c:391 + kref_put include/linux/kref.h:65 [inline] + rxe_create_qp+0x2cd/0x310 drivers/infiniband/sw/rxe/rxe_verbs.c:425 + _ib_create_qp drivers/infiniband/core/core_priv.h:331 [inline] + ib_create_named_qp+0x2ad/0x1370 drivers/infiniband/core/verbs.c:1231 + ib_create_qp include/rdma/ib_verbs.h:3644 [inline] + create_mad_qp+0x177/0x2d0 drivers/infiniband/core/mad.c:2920 + ib_mad_port_open drivers/infiniband/core/mad.c:3001 [inline] + ib_mad_init_device+0xd6f/0x1400 drivers/infiniband/core/mad.c:3092 + add_client_context+0x405/0x5e0 drivers/infiniband/core/device.c:717 + enable_device_and_get+0x1cd/0x3b0 drivers/infiniband/core/device.c:1331 + ib_register_device drivers/infiniband/core/device.c:1413 [inline] + ib_register_device+0x7c7/0xa50 drivers/infiniband/core/device.c:1365 + rxe_register_device+0x3d5/0x4a0 drivers/infiniband/sw/rxe/rxe_verbs.c:1147 + rxe_add+0x12fe/0x16d0 drivers/infiniband/sw/rxe/rxe.c:247 + rxe_net_add+0x8c/0xe0 drivers/infiniband/sw/rxe/rxe_net.c:503 + rxe_newlink drivers/infiniband/sw/rxe/rxe.c:269 [inline] + rxe_newlink+0xb7/0xe0 drivers/infiniband/sw/rxe/rxe.c:250 + nldev_newlink+0x30e/0x550 drivers/infiniband/core/nldev.c:1555 + rdma_nl_rcv_msg+0x36d/0x690 drivers/infiniband/core/netlink.c:195 + rdma_nl_rcv_skb drivers/infiniband/core/netlink.c:239 [inline] + rdma_nl_rcv+0x2ee/0x430 drivers/infiniband/core/netlink.c:259 + netlink_unicast_kernel net/netlink/af_netlink.c:1312 [inline] + netlink_unicast+0x533/0x7d0 net/netlink/af_netlink.c:1338 + netlink_sendmsg+0x856/0xd90 net/netlink/af_netlink.c:1927 + sock_sendmsg_nosec net/socket.c:654 [inline] + sock_sendmsg+0xcf/0x120 net/socket.c:674 + ____sys_sendmsg+0x6e8/0x810 net/socket.c:2350 + ___sys_sendmsg+0xf3/0x170 net/socket.c:2404 + __sys_sendmsg+0xe5/0x1b0 net/socket.c:2433 + do_syscall_64+0x3a/0xb0 arch/x86/entry/common.c:47 + entry_SYSCALL_64_after_hwframe+0x44/0xae + +Fixes: 8700e3e7c485 ("Soft RoCE driver") +Link: https://lore.kernel.org/r/7bf8d548764d406dbbbaf4b574960ebfd5af8387.1620717918.git.leonro@nvidia.com +Reported-by: syzbot+36a7f280de4e11c6f04e@syzkaller.appspotmail.com +Signed-off-by: Leon Romanovsky +Reviewed-by: Zhu Yanjun +Signed-off-by: Jason Gunthorpe +Signed-off-by: Sasha Levin +--- + drivers/infiniband/sw/rxe/rxe_qp.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/drivers/infiniband/sw/rxe/rxe_qp.c b/drivers/infiniband/sw/rxe/rxe_qp.c +index 186da467060c..5fa1442fd4f1 100644 +--- a/drivers/infiniband/sw/rxe/rxe_qp.c ++++ b/drivers/infiniband/sw/rxe/rxe_qp.c +@@ -258,6 +258,7 @@ static int rxe_qp_init_req(struct rxe_dev *rxe, struct rxe_qp *qp, + if (err) { + vfree(qp->sq.queue->buf); + kfree(qp->sq.queue); ++ qp->sq.queue = NULL; + return err; + } + +@@ -315,6 +316,7 @@ static int rxe_qp_init_resp(struct rxe_dev *rxe, struct rxe_qp *qp, + if (err) { + vfree(qp->rq.queue->buf); + kfree(qp->rq.queue); ++ qp->rq.queue = NULL; + return err; + } + } +@@ -374,6 +376,11 @@ int rxe_qp_from_init(struct rxe_dev *rxe, struct rxe_qp *qp, struct rxe_pd *pd, + err2: + rxe_queue_cleanup(qp->sq.queue); + err1: ++ qp->pd = NULL; ++ qp->rcq = NULL; ++ qp->scq = NULL; ++ qp->srq = NULL; ++ + if (srq) + rxe_drop_ref(srq); + rxe_drop_ref(scq); +-- +2.30.2 + diff --git a/queue-4.9/scsi-qla2xxx-fix-error-return-code-in-qla82xx_write_.patch b/queue-4.9/scsi-qla2xxx-fix-error-return-code-in-qla82xx_write_.patch new file mode 100644 index 00000000000..50b5c5d71ef --- /dev/null +++ b/queue-4.9/scsi-qla2xxx-fix-error-return-code-in-qla82xx_write_.patch @@ -0,0 +1,40 @@ +From a1f4ec9ee75b6d37f65c451d5a5d28997cb1474a Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 14 May 2021 17:09:52 +0800 +Subject: scsi: qla2xxx: Fix error return code in qla82xx_write_flash_dword() + +From: Zhen Lei + +[ Upstream commit 5cb289bf2d7c34ca1abd794ce116c4f19185a1d4 ] + +Fix to return a negative error code from the error handling case instead of +0 as done elsewhere in this function. + +Link: https://lore.kernel.org/r/20210514090952.6715-1-thunder.leizhen@huawei.com +Fixes: a9083016a531 ("[SCSI] qla2xxx: Add ISP82XX support.") +Reported-by: Hulk Robot +Reviewed-by: Himanshu Madhani +Signed-off-by: Zhen Lei +Signed-off-by: Martin K. Petersen +Signed-off-by: Sasha Levin +--- + drivers/scsi/qla2xxx/qla_nx.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/drivers/scsi/qla2xxx/qla_nx.c b/drivers/scsi/qla2xxx/qla_nx.c +index 104e13ae3428..9ec18463b452 100644 +--- a/drivers/scsi/qla2xxx/qla_nx.c ++++ b/drivers/scsi/qla2xxx/qla_nx.c +@@ -1102,7 +1102,8 @@ qla82xx_write_flash_dword(struct qla_hw_data *ha, uint32_t flashaddr, + return ret; + } + +- if (qla82xx_flash_set_write_enable(ha)) ++ ret = qla82xx_flash_set_write_enable(ha); ++ if (ret < 0) + goto done_write; + + qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_WDATA, data); +-- +2.30.2 + diff --git a/queue-4.9/series b/queue-4.9/series new file mode 100644 index 00000000000..bdb5cfa436a --- /dev/null +++ b/queue-4.9/series @@ -0,0 +1,4 @@ +openrisc-fix-a-memory-leak.patch +rdma-rxe-clear-all-qp-fields-if-creation-failed.patch +scsi-qla2xxx-fix-error-return-code-in-qla82xx_write_.patch +ptrace-make-ptrace-fail-if-the-tracee-changed-its-pi.patch