From: Greg Kroah-Hartman Date: Mon, 20 Dec 2021 12:26:38 +0000 (+0100) Subject: 5.15-stable patches X-Git-Tag: v4.4.296~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8ffc634dcebe12852f5cbec44105a1d5a948eee1;p=thirdparty%2Fkernel%2Fstable-queue.git 5.15-stable patches added patches: fuse-annotate-lock-in-fuse_reverse_inval_entry.patch io-wq-check-for-wq-exit-after-adding-new-worker-task_work.patch io-wq-remove-spurious-bit-clear-on-task_work-addition.patch ovl-fix-warning-in-ovl_create_real.patch rcu-mark-accesses-to-rcu_state.n_force_qs.patch scsi-scsi_debug-don-t-call-kcalloc-if-size-arg-is-zero.patch scsi-scsi_debug-fix-type-in-min_t-to-avoid-stack-oob.patch scsi-scsi_debug-sanity-check-block-descriptor-length-in-resp_mode_select.patch --- diff --git a/queue-5.15/fuse-annotate-lock-in-fuse_reverse_inval_entry.patch b/queue-5.15/fuse-annotate-lock-in-fuse_reverse_inval_entry.patch new file mode 100644 index 00000000000..52d008103a5 --- /dev/null +++ b/queue-5.15/fuse-annotate-lock-in-fuse_reverse_inval_entry.patch @@ -0,0 +1,29 @@ +From bda9a71980e083699a0360963c0135657b73f47a Mon Sep 17 00:00:00 2001 +From: Miklos Szeredi +Date: Fri, 22 Oct 2021 17:03:01 +0200 +Subject: fuse: annotate lock in fuse_reverse_inval_entry() + +From: Miklos Szeredi + +commit bda9a71980e083699a0360963c0135657b73f47a upstream. + +Add missing inode lock annotatation; found by syzbot. + +Reported-and-tested-by: syzbot+9f747458f5990eaa8d43@syzkaller.appspotmail.com +Signed-off-by: Miklos Szeredi +Signed-off-by: Greg Kroah-Hartman +--- + fs/fuse/dir.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/fs/fuse/dir.c ++++ b/fs/fuse/dir.c +@@ -1079,7 +1079,7 @@ int fuse_reverse_inval_entry(struct fuse + if (!parent) + return -ENOENT; + +- inode_lock(parent); ++ inode_lock_nested(parent, I_MUTEX_PARENT); + if (!S_ISDIR(parent->i_mode)) + goto unlock; + diff --git a/queue-5.15/io-wq-check-for-wq-exit-after-adding-new-worker-task_work.patch b/queue-5.15/io-wq-check-for-wq-exit-after-adding-new-worker-task_work.patch new file mode 100644 index 00000000000..5a5c24a5921 --- /dev/null +++ b/queue-5.15/io-wq-check-for-wq-exit-after-adding-new-worker-task_work.patch @@ -0,0 +1,93 @@ +From 71a85387546e50b1a37b0fa45dadcae3bfb35cf6 Mon Sep 17 00:00:00 2001 +From: Jens Axboe +Date: Fri, 10 Dec 2021 08:29:30 -0700 +Subject: io-wq: check for wq exit after adding new worker task_work + +From: Jens Axboe + +commit 71a85387546e50b1a37b0fa45dadcae3bfb35cf6 upstream. + +We check IO_WQ_BIT_EXIT before attempting to create a new worker, and +wq exit cancels pending work if we have any. But it's possible to have +a race between the two, where creation checks exit finding it not set, +but we're in the process of exiting. The exit side will cancel pending +creation task_work, but there's a gap where we add task_work after we've +canceled existing creations at exit time. + +Fix this by checking the EXIT bit post adding the creation task_work. +If it's set, run the same cancelation that exit does. + +Reported-and-tested-by: syzbot+b60c982cb0efc5e05a47@syzkaller.appspotmail.com +Reviewed-by: Hao Xu +Signed-off-by: Jens Axboe +Signed-off-by: Greg Kroah-Hartman +--- + fs/io-wq.c | 31 +++++++++++++++++++++++++------ + 1 file changed, 25 insertions(+), 6 deletions(-) + +--- a/fs/io-wq.c ++++ b/fs/io-wq.c +@@ -141,6 +141,7 @@ static bool io_acct_cancel_pending_work( + struct io_wqe_acct *acct, + struct io_cb_cancel_data *match); + static void create_worker_cb(struct callback_head *cb); ++static void io_wq_cancel_tw_create(struct io_wq *wq); + + static bool io_worker_get(struct io_worker *worker) + { +@@ -357,10 +358,22 @@ static bool io_queue_worker_create(struc + test_and_set_bit_lock(0, &worker->create_state)) + goto fail_release; + ++ atomic_inc(&wq->worker_refs); + init_task_work(&worker->create_work, func); + worker->create_index = acct->index; +- if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL)) ++ if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL)) { ++ /* ++ * EXIT may have been set after checking it above, check after ++ * adding the task_work and remove any creation item if it is ++ * now set. wq exit does that too, but we can have added this ++ * work item after we canceled in io_wq_exit_workers(). ++ */ ++ if (test_bit(IO_WQ_BIT_EXIT, &wq->state)) ++ io_wq_cancel_tw_create(wq); ++ io_worker_ref_put(wq); + return true; ++ } ++ io_worker_ref_put(wq); + clear_bit_unlock(0, &worker->create_state); + fail_release: + io_worker_release(worker); +@@ -1193,13 +1206,9 @@ void io_wq_exit_start(struct io_wq *wq) + set_bit(IO_WQ_BIT_EXIT, &wq->state); + } + +-static void io_wq_exit_workers(struct io_wq *wq) ++static void io_wq_cancel_tw_create(struct io_wq *wq) + { + struct callback_head *cb; +- int node; +- +- if (!wq->task) +- return; + + while ((cb = task_work_cancel_match(wq->task, io_task_work_match, wq)) != NULL) { + struct io_worker *worker; +@@ -1207,6 +1216,16 @@ static void io_wq_exit_workers(struct io + worker = container_of(cb, struct io_worker, create_work); + io_worker_cancel_cb(worker); + } ++} ++ ++static void io_wq_exit_workers(struct io_wq *wq) ++{ ++ int node; ++ ++ if (!wq->task) ++ return; ++ ++ io_wq_cancel_tw_create(wq); + + rcu_read_lock(); + for_each_node(node) { diff --git a/queue-5.15/io-wq-remove-spurious-bit-clear-on-task_work-addition.patch b/queue-5.15/io-wq-remove-spurious-bit-clear-on-task_work-addition.patch new file mode 100644 index 00000000000..4d569d29b74 --- /dev/null +++ b/queue-5.15/io-wq-remove-spurious-bit-clear-on-task_work-addition.patch @@ -0,0 +1,37 @@ +From e47498afeca9a0c6d07eeeacc46d563555a3f677 Mon Sep 17 00:00:00 2001 +From: Jens Axboe +Date: Mon, 6 Dec 2021 10:49:04 -0700 +Subject: io-wq: remove spurious bit clear on task_work addition + +From: Jens Axboe + +commit e47498afeca9a0c6d07eeeacc46d563555a3f677 upstream. + +There's a small race here where the task_work could finish and drop +the worker itself, so that by the time that task_work_add() returns +with a successful addition we've already put the worker. + +The worker callbacks clear this bit themselves, so we don't actually +need to manually clear it in the caller. Get rid of it. + +Reported-by: syzbot+b60c982cb0efc5e05a47@syzkaller.appspotmail.com +Signed-off-by: Jens Axboe +Signed-off-by: Greg Kroah-Hartman +--- + fs/io-wq.c | 4 +--- + 1 file changed, 1 insertion(+), 3 deletions(-) + +--- a/fs/io-wq.c ++++ b/fs/io-wq.c +@@ -359,10 +359,8 @@ static bool io_queue_worker_create(struc + + init_task_work(&worker->create_work, func); + worker->create_index = acct->index; +- if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL)) { +- clear_bit_unlock(0, &worker->create_state); ++ if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL)) + return true; +- } + clear_bit_unlock(0, &worker->create_state); + fail_release: + io_worker_release(worker); diff --git a/queue-5.15/ovl-fix-warning-in-ovl_create_real.patch b/queue-5.15/ovl-fix-warning-in-ovl_create_real.patch new file mode 100644 index 00000000000..c971a2e9702 --- /dev/null +++ b/queue-5.15/ovl-fix-warning-in-ovl_create_real.patch @@ -0,0 +1,73 @@ +From 1f5573cfe7a7056e80a92c7a037a3e69f3a13d1c Mon Sep 17 00:00:00 2001 +From: Miklos Szeredi +Date: Thu, 4 Nov 2021 10:55:34 +0100 +Subject: ovl: fix warning in ovl_create_real() + +From: Miklos Szeredi + +commit 1f5573cfe7a7056e80a92c7a037a3e69f3a13d1c upstream. + +Syzbot triggered the following warning in ovl_workdir_create() -> +ovl_create_real(): + + if (!err && WARN_ON(!newdentry->d_inode)) { + +The reason is that the cgroup2 filesystem returns from mkdir without +instantiating the new dentry. + +Weird filesystems such as this will be rejected by overlayfs at a later +stage during setup, but to prevent such a warning, call ovl_mkdir_real() +directly from ovl_workdir_create() and reject this case early. + +Reported-and-tested-by: syzbot+75eab84fd0af9e8bf66b@syzkaller.appspotmail.com +Signed-off-by: Miklos Szeredi +Signed-off-by: Greg Kroah-Hartman +--- + fs/overlayfs/dir.c | 3 +-- + fs/overlayfs/overlayfs.h | 1 + + fs/overlayfs/super.c | 12 ++++++++---- + 3 files changed, 10 insertions(+), 6 deletions(-) + +--- a/fs/overlayfs/dir.c ++++ b/fs/overlayfs/dir.c +@@ -137,8 +137,7 @@ kill_whiteout: + goto out; + } + +-static int ovl_mkdir_real(struct inode *dir, struct dentry **newdentry, +- umode_t mode) ++int ovl_mkdir_real(struct inode *dir, struct dentry **newdentry, umode_t mode) + { + int err; + struct dentry *d, *dentry = *newdentry; +--- a/fs/overlayfs/overlayfs.h ++++ b/fs/overlayfs/overlayfs.h +@@ -570,6 +570,7 @@ struct ovl_cattr { + + #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) }) + ++int ovl_mkdir_real(struct inode *dir, struct dentry **newdentry, umode_t mode); + struct dentry *ovl_create_real(struct inode *dir, struct dentry *newdentry, + struct ovl_cattr *attr); + int ovl_cleanup(struct inode *dir, struct dentry *dentry); +--- a/fs/overlayfs/super.c ++++ b/fs/overlayfs/super.c +@@ -787,10 +787,14 @@ retry: + goto retry; + } + +- work = ovl_create_real(dir, work, OVL_CATTR(attr.ia_mode)); +- err = PTR_ERR(work); +- if (IS_ERR(work)) +- goto out_err; ++ err = ovl_mkdir_real(dir, &work, attr.ia_mode); ++ if (err) ++ goto out_dput; ++ ++ /* Weird filesystem returning with hashed negative (kernfs)? */ ++ err = -EINVAL; ++ if (d_really_is_negative(work)) ++ goto out_dput; + + /* + * Try to remove POSIX ACL xattrs from workdir. We are good if: diff --git a/queue-5.15/rcu-mark-accesses-to-rcu_state.n_force_qs.patch b/queue-5.15/rcu-mark-accesses-to-rcu_state.n_force_qs.patch new file mode 100644 index 00000000000..79f9f93cde4 --- /dev/null +++ b/queue-5.15/rcu-mark-accesses-to-rcu_state.n_force_qs.patch @@ -0,0 +1,62 @@ +From 2431774f04d1050292054c763070021bade7b151 Mon Sep 17 00:00:00 2001 +From: "Paul E. McKenney" +Date: Tue, 20 Jul 2021 06:16:27 -0700 +Subject: rcu: Mark accesses to rcu_state.n_force_qs + +From: Paul E. McKenney + +commit 2431774f04d1050292054c763070021bade7b151 upstream. + +This commit marks accesses to the rcu_state.n_force_qs. These data +races are hard to make happen, but syzkaller was equal to the task. + +Reported-by: syzbot+e08a83a1940ec3846cd5@syzkaller.appspotmail.com +Acked-by: Marco Elver +Signed-off-by: Paul E. McKenney +Signed-off-by: Greg Kroah-Hartman +--- + kernel/rcu/tree.c | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +--- a/kernel/rcu/tree.c ++++ b/kernel/rcu/tree.c +@@ -1907,7 +1907,7 @@ static void rcu_gp_fqs(bool first_time) + struct rcu_node *rnp = rcu_get_root(); + + WRITE_ONCE(rcu_state.gp_activity, jiffies); +- rcu_state.n_force_qs++; ++ WRITE_ONCE(rcu_state.n_force_qs, rcu_state.n_force_qs + 1); + if (first_time) { + /* Collect dyntick-idle snapshots. */ + force_qs_rnp(dyntick_save_progress_counter); +@@ -2550,7 +2550,7 @@ static void rcu_do_batch(struct rcu_data + /* Reset ->qlen_last_fqs_check trigger if enough CBs have drained. */ + if (count == 0 && rdp->qlen_last_fqs_check != 0) { + rdp->qlen_last_fqs_check = 0; +- rdp->n_force_qs_snap = rcu_state.n_force_qs; ++ rdp->n_force_qs_snap = READ_ONCE(rcu_state.n_force_qs); + } else if (count < rdp->qlen_last_fqs_check - qhimark) + rdp->qlen_last_fqs_check = count; + +@@ -2898,10 +2898,10 @@ static void __call_rcu_core(struct rcu_d + } else { + /* Give the grace period a kick. */ + rdp->blimit = DEFAULT_MAX_RCU_BLIMIT; +- if (rcu_state.n_force_qs == rdp->n_force_qs_snap && ++ if (READ_ONCE(rcu_state.n_force_qs) == rdp->n_force_qs_snap && + rcu_segcblist_first_pend_cb(&rdp->cblist) != head) + rcu_force_quiescent_state(); +- rdp->n_force_qs_snap = rcu_state.n_force_qs; ++ rdp->n_force_qs_snap = READ_ONCE(rcu_state.n_force_qs); + rdp->qlen_last_fqs_check = rcu_segcblist_n_cbs(&rdp->cblist); + } + } +@@ -4128,7 +4128,7 @@ int rcutree_prepare_cpu(unsigned int cpu + /* Set up local state, ensuring consistent view of global state. */ + raw_spin_lock_irqsave_rcu_node(rnp, flags); + rdp->qlen_last_fqs_check = 0; +- rdp->n_force_qs_snap = rcu_state.n_force_qs; ++ rdp->n_force_qs_snap = READ_ONCE(rcu_state.n_force_qs); + rdp->blimit = blimit; + rdp->dynticks_nesting = 1; /* CPU not up, no tearing. */ + rcu_dynticks_eqs_online(); diff --git a/queue-5.15/scsi-scsi_debug-don-t-call-kcalloc-if-size-arg-is-zero.patch b/queue-5.15/scsi-scsi_debug-don-t-call-kcalloc-if-size-arg-is-zero.patch new file mode 100644 index 00000000000..0a0ef49b079 --- /dev/null +++ b/queue-5.15/scsi-scsi_debug-don-t-call-kcalloc-if-size-arg-is-zero.patch @@ -0,0 +1,88 @@ +From 3344b58b53a76199dae48faa396e9fc37bf86992 Mon Sep 17 00:00:00 2001 +From: George Kennedy +Date: Thu, 4 Nov 2021 15:06:37 -0500 +Subject: scsi: scsi_debug: Don't call kcalloc() if size arg is zero + +From: George Kennedy + +commit 3344b58b53a76199dae48faa396e9fc37bf86992 upstream. + +If the size arg to kcalloc() is zero, it returns ZERO_SIZE_PTR. Because of +that, for a following NULL pointer check to work on the returned pointer, +kcalloc() must not be called with the size arg equal to zero. Return early +without error before the kcalloc() call if size arg is zero. + +BUG: KASAN: null-ptr-deref in memcpy include/linux/fortify-string.h:191 [inline] +BUG: KASAN: null-ptr-deref in sg_copy_buffer+0x138/0x240 lib/scatterlist.c:974 +Write of size 4 at addr 0000000000000010 by task syz-executor.1/22789 + +CPU: 1 PID: 22789 Comm: syz-executor.1 Not tainted 5.15.0-syzk #1 +Hardware name: Red Hat KVM, BIOS 1.13.0-2 +Call Trace: + __dump_stack lib/dump_stack.c:88 [inline] + dump_stack_lvl+0x89/0xb5 lib/dump_stack.c:106 + __kasan_report mm/kasan/report.c:446 [inline] + kasan_report.cold.14+0x112/0x117 mm/kasan/report.c:459 + check_region_inline mm/kasan/generic.c:183 [inline] + kasan_check_range+0x1a3/0x210 mm/kasan/generic.c:189 + memcpy+0x3b/0x60 mm/kasan/shadow.c:66 + memcpy include/linux/fortify-string.h:191 [inline] + sg_copy_buffer+0x138/0x240 lib/scatterlist.c:974 + do_dout_fetch drivers/scsi/scsi_debug.c:2954 [inline] + do_dout_fetch drivers/scsi/scsi_debug.c:2946 [inline] + resp_verify+0x49e/0x930 drivers/scsi/scsi_debug.c:4276 + schedule_resp+0x4d8/0x1a70 drivers/scsi/scsi_debug.c:5478 + scsi_debug_queuecommand+0x8c9/0x1ec0 drivers/scsi/scsi_debug.c:7533 + scsi_dispatch_cmd drivers/scsi/scsi_lib.c:1520 [inline] + scsi_queue_rq+0x16b0/0x2d40 drivers/scsi/scsi_lib.c:1699 + blk_mq_dispatch_rq_list+0xb9b/0x2700 block/blk-mq.c:1639 + __blk_mq_sched_dispatch_requests+0x28f/0x590 block/blk-mq-sched.c:325 + blk_mq_sched_dispatch_requests+0x105/0x190 block/blk-mq-sched.c:358 + __blk_mq_run_hw_queue+0xe5/0x150 block/blk-mq.c:1761 + __blk_mq_delay_run_hw_queue+0x4f8/0x5c0 block/blk-mq.c:1838 + blk_mq_run_hw_queue+0x18d/0x350 block/blk-mq.c:1891 + blk_mq_sched_insert_request+0x3db/0x4e0 block/blk-mq-sched.c:474 + blk_execute_rq_nowait+0x16b/0x1c0 block/blk-exec.c:62 + blk_execute_rq+0xdb/0x360 block/blk-exec.c:102 + sg_scsi_ioctl drivers/scsi/scsi_ioctl.c:621 [inline] + scsi_ioctl+0x8bb/0x15c0 drivers/scsi/scsi_ioctl.c:930 + sg_ioctl_common+0x172d/0x2710 drivers/scsi/sg.c:1112 + sg_ioctl+0xa2/0x180 drivers/scsi/sg.c:1165 + vfs_ioctl fs/ioctl.c:51 [inline] + __do_sys_ioctl fs/ioctl.c:874 [inline] + __se_sys_ioctl fs/ioctl.c:860 [inline] + __x64_sys_ioctl+0x19d/0x220 fs/ioctl.c:860 + do_syscall_x64 arch/x86/entry/common.c:50 [inline] + do_syscall_64+0x3a/0x80 arch/x86/entry/common.c:80 + entry_SYSCALL_64_after_hwframe+0x44/0xae + +Link: https://lore.kernel.org/r/1636056397-13151-1-git-send-email-george.kennedy@oracle.com +Reported-by: syzkaller +Acked-by: Douglas Gilbert +Signed-off-by: George Kennedy +Signed-off-by: Martin K. Petersen +Signed-off-by: Greg Kroah-Hartman +--- + drivers/scsi/scsi_debug.c | 4 ++++ + 1 file changed, 4 insertions(+) + +--- a/drivers/scsi/scsi_debug.c ++++ b/drivers/scsi/scsi_debug.c +@@ -4259,6 +4259,8 @@ static int resp_verify(struct scsi_cmnd + mk_sense_invalid_opcode(scp); + return check_condition_result; + } ++ if (vnum == 0) ++ return 0; /* not an error */ + a_num = is_bytchk3 ? 1 : vnum; + /* Treat following check like one for read (i.e. no write) access */ + ret = check_device_access_params(scp, lba, a_num, false); +@@ -4322,6 +4324,8 @@ static int resp_report_zones(struct scsi + } + zs_lba = get_unaligned_be64(cmd + 2); + alloc_len = get_unaligned_be32(cmd + 10); ++ if (alloc_len == 0) ++ return 0; /* not an error */ + rep_opts = cmd[14] & 0x3f; + partial = cmd[14] & 0x80; + diff --git a/queue-5.15/scsi-scsi_debug-fix-type-in-min_t-to-avoid-stack-oob.patch b/queue-5.15/scsi-scsi_debug-fix-type-in-min_t-to-avoid-stack-oob.patch new file mode 100644 index 00000000000..8cf6ff5893c --- /dev/null +++ b/queue-5.15/scsi-scsi_debug-fix-type-in-min_t-to-avoid-stack-oob.patch @@ -0,0 +1,190 @@ +From 36e07d7ede88a1f1ef8f0f209af5b7612324ac2c Mon Sep 17 00:00:00 2001 +From: George Kennedy +Date: Tue, 9 Nov 2021 13:57:27 -0500 +Subject: scsi: scsi_debug: Fix type in min_t to avoid stack OOB + +From: George Kennedy + +commit 36e07d7ede88a1f1ef8f0f209af5b7612324ac2c upstream. + +Change min_t() to use type "u32" instead of type "int" to avoid stack out +of bounds. With min_t() type "int" the values get sign extended and the +larger value gets used causing stack out of bounds. + +BUG: KASAN: stack-out-of-bounds in memcpy include/linux/fortify-string.h:191 [inline] +BUG: KASAN: stack-out-of-bounds in sg_copy_buffer+0x1de/0x240 lib/scatterlist.c:976 +Read of size 127 at addr ffff888072607128 by task syz-executor.7/18707 + +CPU: 1 PID: 18707 Comm: syz-executor.7 Not tainted 5.15.0-syzk #1 +Hardware name: Red Hat KVM, BIOS 1.13.0-2 +Call Trace: + __dump_stack lib/dump_stack.c:88 [inline] + dump_stack_lvl+0x89/0xb5 lib/dump_stack.c:106 + print_address_description.constprop.9+0x28/0x160 mm/kasan/report.c:256 + __kasan_report mm/kasan/report.c:442 [inline] + kasan_report.cold.14+0x7d/0x117 mm/kasan/report.c:459 + check_region_inline mm/kasan/generic.c:183 [inline] + kasan_check_range+0x1a3/0x210 mm/kasan/generic.c:189 + memcpy+0x23/0x60 mm/kasan/shadow.c:65 + memcpy include/linux/fortify-string.h:191 [inline] + sg_copy_buffer+0x1de/0x240 lib/scatterlist.c:976 + sg_copy_from_buffer+0x33/0x40 lib/scatterlist.c:1000 + fill_from_dev_buffer.part.34+0x82/0x130 drivers/scsi/scsi_debug.c:1162 + fill_from_dev_buffer drivers/scsi/scsi_debug.c:1888 [inline] + resp_readcap16+0x365/0x3b0 drivers/scsi/scsi_debug.c:1887 + schedule_resp+0x4d8/0x1a70 drivers/scsi/scsi_debug.c:5478 + scsi_debug_queuecommand+0x8c9/0x1ec0 drivers/scsi/scsi_debug.c:7533 + scsi_dispatch_cmd drivers/scsi/scsi_lib.c:1520 [inline] + scsi_queue_rq+0x16b0/0x2d40 drivers/scsi/scsi_lib.c:1699 + blk_mq_dispatch_rq_list+0xb9b/0x2700 block/blk-mq.c:1639 + __blk_mq_sched_dispatch_requests+0x28f/0x590 block/blk-mq-sched.c:325 + blk_mq_sched_dispatch_requests+0x105/0x190 block/blk-mq-sched.c:358 + __blk_mq_run_hw_queue+0xe5/0x150 block/blk-mq.c:1761 + __blk_mq_delay_run_hw_queue+0x4f8/0x5c0 block/blk-mq.c:1838 + blk_mq_run_hw_queue+0x18d/0x350 block/blk-mq.c:1891 + blk_mq_sched_insert_request+0x3db/0x4e0 block/blk-mq-sched.c:474 + blk_execute_rq_nowait+0x16b/0x1c0 block/blk-exec.c:62 + sg_common_write.isra.18+0xeb3/0x2000 drivers/scsi/sg.c:836 + sg_new_write.isra.19+0x570/0x8c0 drivers/scsi/sg.c:774 + sg_ioctl_common+0x14d6/0x2710 drivers/scsi/sg.c:939 + sg_ioctl+0xa2/0x180 drivers/scsi/sg.c:1165 + vfs_ioctl fs/ioctl.c:51 [inline] + __do_sys_ioctl fs/ioctl.c:874 [inline] + __se_sys_ioctl fs/ioctl.c:860 [inline] + __x64_sys_ioctl+0x19d/0x220 fs/ioctl.c:860 + do_syscall_x64 arch/x86/entry/common.c:50 [inline] + do_syscall_64+0x3a/0x80 arch/x86/entry/common.c:80 + entry_SYSCALL_64_after_hwframe+0x44/0xae + +Link: https://lore.kernel.org/r/1636484247-21254-1-git-send-email-george.kennedy@oracle.com +Reported-by: syzkaller +Acked-by: Douglas Gilbert +Signed-off-by: George Kennedy +Signed-off-by: Martin K. Petersen +Signed-off-by: Greg Kroah-Hartman +--- + drivers/scsi/scsi_debug.c | 34 +++++++++++++++++++--------------- + 1 file changed, 19 insertions(+), 15 deletions(-) + +--- a/drivers/scsi/scsi_debug.c ++++ b/drivers/scsi/scsi_debug.c +@@ -1189,7 +1189,7 @@ static int p_fill_from_dev_buffer(struct + __func__, off_dst, scsi_bufflen(scp), act_len, + scsi_get_resid(scp)); + n = scsi_bufflen(scp) - (off_dst + act_len); +- scsi_set_resid(scp, min_t(int, scsi_get_resid(scp), n)); ++ scsi_set_resid(scp, min_t(u32, scsi_get_resid(scp), n)); + return 0; + } + +@@ -1562,7 +1562,8 @@ static int resp_inquiry(struct scsi_cmnd + unsigned char pq_pdt; + unsigned char *arr; + unsigned char *cmd = scp->cmnd; +- int alloc_len, n, ret; ++ u32 alloc_len, n; ++ int ret; + bool have_wlun, is_disk, is_zbc, is_disk_zbc; + + alloc_len = get_unaligned_be16(cmd + 3); +@@ -1585,7 +1586,8 @@ static int resp_inquiry(struct scsi_cmnd + kfree(arr); + return check_condition_result; + } else if (0x1 & cmd[1]) { /* EVPD bit set */ +- int lu_id_num, port_group_id, target_dev_id, len; ++ int lu_id_num, port_group_id, target_dev_id; ++ u32 len; + char lu_id_str[6]; + int host_no = devip->sdbg_host->shost->host_no; + +@@ -1676,9 +1678,9 @@ static int resp_inquiry(struct scsi_cmnd + kfree(arr); + return check_condition_result; + } +- len = min(get_unaligned_be16(arr + 2) + 4, alloc_len); ++ len = min_t(u32, get_unaligned_be16(arr + 2) + 4, alloc_len); + ret = fill_from_dev_buffer(scp, arr, +- min(len, SDEBUG_MAX_INQ_ARR_SZ)); ++ min_t(u32, len, SDEBUG_MAX_INQ_ARR_SZ)); + kfree(arr); + return ret; + } +@@ -1714,7 +1716,7 @@ static int resp_inquiry(struct scsi_cmnd + } + put_unaligned_be16(0x2100, arr + n); /* SPL-4 no version claimed */ + ret = fill_from_dev_buffer(scp, arr, +- min_t(int, alloc_len, SDEBUG_LONG_INQ_SZ)); ++ min_t(u32, alloc_len, SDEBUG_LONG_INQ_SZ)); + kfree(arr); + return ret; + } +@@ -1729,8 +1731,8 @@ static int resp_requests(struct scsi_cmn + unsigned char *cmd = scp->cmnd; + unsigned char arr[SCSI_SENSE_BUFFERSIZE]; /* assume >= 18 bytes */ + bool dsense = !!(cmd[1] & 1); +- int alloc_len = cmd[4]; +- int len = 18; ++ u32 alloc_len = cmd[4]; ++ u32 len = 18; + int stopped_state = atomic_read(&devip->stopped); + + memset(arr, 0, sizeof(arr)); +@@ -1774,7 +1776,7 @@ static int resp_requests(struct scsi_cmn + arr[7] = 0xa; + } + } +- return fill_from_dev_buffer(scp, arr, min_t(int, len, alloc_len)); ++ return fill_from_dev_buffer(scp, arr, min_t(u32, len, alloc_len)); + } + + static int resp_start_stop(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) +@@ -2312,7 +2314,8 @@ static int resp_mode_sense(struct scsi_c + { + int pcontrol, pcode, subpcode, bd_len; + unsigned char dev_spec; +- int alloc_len, offset, len, target_dev_id; ++ u32 alloc_len, offset, len; ++ int target_dev_id; + int target = scp->device->id; + unsigned char *ap; + unsigned char arr[SDEBUG_MAX_MSENSE_SZ]; +@@ -2468,7 +2471,7 @@ static int resp_mode_sense(struct scsi_c + arr[0] = offset - 1; + else + put_unaligned_be16((offset - 2), arr + 0); +- return fill_from_dev_buffer(scp, arr, min_t(int, alloc_len, offset)); ++ return fill_from_dev_buffer(scp, arr, min_t(u32, alloc_len, offset)); + } + + #define SDEBUG_MAX_MSELECT_SZ 512 +@@ -2583,7 +2586,8 @@ static int resp_ie_l_pg(unsigned char *a + static int resp_log_sense(struct scsi_cmnd *scp, + struct sdebug_dev_info *devip) + { +- int ppc, sp, pcode, subpcode, alloc_len, len, n; ++ int ppc, sp, pcode, subpcode; ++ u32 alloc_len, len, n; + unsigned char arr[SDEBUG_MAX_LSENSE_SZ]; + unsigned char *cmd = scp->cmnd; + +@@ -2653,9 +2657,9 @@ static int resp_log_sense(struct scsi_cm + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); + return check_condition_result; + } +- len = min_t(int, get_unaligned_be16(arr + 2) + 4, alloc_len); ++ len = min_t(u32, get_unaligned_be16(arr + 2) + 4, alloc_len); + return fill_from_dev_buffer(scp, arr, +- min_t(int, len, SDEBUG_MAX_INQ_ARR_SZ)); ++ min_t(u32, len, SDEBUG_MAX_INQ_ARR_SZ)); + } + + static inline bool sdebug_dev_is_zoned(struct sdebug_dev_info *devip) +@@ -4430,7 +4434,7 @@ static int resp_report_zones(struct scsi + put_unaligned_be64(sdebug_capacity - 1, arr + 8); + + rep_len = (unsigned long)desc - (unsigned long)arr; +- ret = fill_from_dev_buffer(scp, arr, min_t(int, alloc_len, rep_len)); ++ ret = fill_from_dev_buffer(scp, arr, min_t(u32, alloc_len, rep_len)); + + fini: + read_unlock(macc_lckp); diff --git a/queue-5.15/scsi-scsi_debug-sanity-check-block-descriptor-length-in-resp_mode_select.patch b/queue-5.15/scsi-scsi_debug-sanity-check-block-descriptor-length-in-resp_mode_select.patch new file mode 100644 index 00000000000..43178321664 --- /dev/null +++ b/queue-5.15/scsi-scsi_debug-sanity-check-block-descriptor-length-in-resp_mode_select.patch @@ -0,0 +1,68 @@ +From e0a2c28da11e2c2b963fc01d50acbf03045ac732 Mon Sep 17 00:00:00 2001 +From: George Kennedy +Date: Thu, 18 Nov 2021 14:03:28 -0500 +Subject: scsi: scsi_debug: Sanity check block descriptor length in resp_mode_select() + +From: George Kennedy + +commit e0a2c28da11e2c2b963fc01d50acbf03045ac732 upstream. + +In resp_mode_select() sanity check the block descriptor len to avoid UAF. + +BUG: KASAN: use-after-free in resp_mode_select+0xa4c/0xb40 drivers/scsi/scsi_debug.c:2509 +Read of size 1 at addr ffff888026670f50 by task scsicmd/15032 + +CPU: 1 PID: 15032 Comm: scsicmd Not tainted 5.15.0-01d0625 #15 +Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS +Call Trace: + + dump_stack_lvl+0x89/0xb5 lib/dump_stack.c:107 + print_address_description.constprop.9+0x28/0x160 mm/kasan/report.c:257 + kasan_report.cold.14+0x7d/0x117 mm/kasan/report.c:443 + __asan_report_load1_noabort+0x14/0x20 mm/kasan/report_generic.c:306 + resp_mode_select+0xa4c/0xb40 drivers/scsi/scsi_debug.c:2509 + schedule_resp+0x4af/0x1a10 drivers/scsi/scsi_debug.c:5483 + scsi_debug_queuecommand+0x8c9/0x1e70 drivers/scsi/scsi_debug.c:7537 + scsi_queue_rq+0x16b4/0x2d10 drivers/scsi/scsi_lib.c:1521 + blk_mq_dispatch_rq_list+0xb9b/0x2700 block/blk-mq.c:1640 + __blk_mq_sched_dispatch_requests+0x28f/0x590 block/blk-mq-sched.c:325 + blk_mq_sched_dispatch_requests+0x105/0x190 block/blk-mq-sched.c:358 + __blk_mq_run_hw_queue+0xe5/0x150 block/blk-mq.c:1762 + __blk_mq_delay_run_hw_queue+0x4f8/0x5c0 block/blk-mq.c:1839 + blk_mq_run_hw_queue+0x18d/0x350 block/blk-mq.c:1891 + blk_mq_sched_insert_request+0x3db/0x4e0 block/blk-mq-sched.c:474 + blk_execute_rq_nowait+0x16b/0x1c0 block/blk-exec.c:63 + sg_common_write.isra.18+0xeb3/0x2000 drivers/scsi/sg.c:837 + sg_new_write.isra.19+0x570/0x8c0 drivers/scsi/sg.c:775 + sg_ioctl_common+0x14d6/0x2710 drivers/scsi/sg.c:941 + sg_ioctl+0xa2/0x180 drivers/scsi/sg.c:1166 + __x64_sys_ioctl+0x19d/0x220 fs/ioctl.c:52 + do_syscall_64+0x3a/0x80 arch/x86/entry/common.c:50 + entry_SYSCALL_64_after_hwframe+0x44/0xae arch/x86/entry/entry_64.S:113 + +Link: https://lore.kernel.org/r/1637262208-28850-1-git-send-email-george.kennedy@oracle.com +Reported-by: syzkaller +Acked-by: Douglas Gilbert +Signed-off-by: George Kennedy +Signed-off-by: Martin K. Petersen +Signed-off-by: Greg Kroah-Hartman +--- + drivers/scsi/scsi_debug.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +--- a/drivers/scsi/scsi_debug.c ++++ b/drivers/scsi/scsi_debug.c +@@ -2502,11 +2502,11 @@ static int resp_mode_select(struct scsi_ + __func__, param_len, res); + md_len = mselect6 ? (arr[0] + 1) : (get_unaligned_be16(arr + 0) + 2); + bd_len = mselect6 ? arr[3] : get_unaligned_be16(arr + 6); +- if (md_len > 2) { ++ off = bd_len + (mselect6 ? 4 : 8); ++ if (md_len > 2 || off >= res) { + mk_sense_invalid_fld(scp, SDEB_IN_DATA, 0, -1); + return check_condition_result; + } +- off = bd_len + (mselect6 ? 4 : 8); + mpage = arr[off] & 0x3f; + ps = !!(arr[off] & 0x80); + if (ps) { diff --git a/queue-5.15/series b/queue-5.15/series index e4150c7e982..7fe3e0e9915 100644 --- a/queue-5.15/series +++ b/queue-5.15/series @@ -158,3 +158,11 @@ bpf-x64-factor-out-emission-of-rex-byte-in-more-cases.patch bpf-fix-extable-address-check.patch usb-core-make-do_proc_control-and-do_proc_bulk-killable.patch media-mxl111sf-change-mutex_init-location.patch +fuse-annotate-lock-in-fuse_reverse_inval_entry.patch +ovl-fix-warning-in-ovl_create_real.patch +scsi-scsi_debug-don-t-call-kcalloc-if-size-arg-is-zero.patch +scsi-scsi_debug-fix-type-in-min_t-to-avoid-stack-oob.patch +scsi-scsi_debug-sanity-check-block-descriptor-length-in-resp_mode_select.patch +io-wq-remove-spurious-bit-clear-on-task_work-addition.patch +io-wq-check-for-wq-exit-after-adding-new-worker-task_work.patch +rcu-mark-accesses-to-rcu_state.n_force_qs.patch