From b2dcc00972092c2cf8985607ee581316d91a87d2 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 20 Dec 2021 13:32:12 +0100 Subject: [PATCH] 5.10-stable patches added patches: fuse-annotate-lock-in-fuse_reverse_inval_entry.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 --- ...ate-lock-in-fuse_reverse_inval_entry.patch | 29 +++ .../ovl-fix-warning-in-ovl_create_real.patch | 73 +++++++ ...ark-accesses-to-rcu_state.n_force_qs.patch | 62 ++++++ ...n-t-call-kcalloc-if-size-arg-is-zero.patch | 88 ++++++++ ...fix-type-in-min_t-to-avoid-stack-oob.patch | 190 ++++++++++++++++++ ...escriptor-length-in-resp_mode_select.patch | 68 +++++++ queue-5.10/series | 6 + 7 files changed, 516 insertions(+) create mode 100644 queue-5.10/fuse-annotate-lock-in-fuse_reverse_inval_entry.patch create mode 100644 queue-5.10/ovl-fix-warning-in-ovl_create_real.patch create mode 100644 queue-5.10/rcu-mark-accesses-to-rcu_state.n_force_qs.patch create mode 100644 queue-5.10/scsi-scsi_debug-don-t-call-kcalloc-if-size-arg-is-zero.patch create mode 100644 queue-5.10/scsi-scsi_debug-fix-type-in-min_t-to-avoid-stack-oob.patch create mode 100644 queue-5.10/scsi-scsi_debug-sanity-check-block-descriptor-length-in-resp_mode_select.patch diff --git a/queue-5.10/fuse-annotate-lock-in-fuse_reverse_inval_entry.patch b/queue-5.10/fuse-annotate-lock-in-fuse_reverse_inval_entry.patch new file mode 100644 index 00000000000..236d4aa8863 --- /dev/null +++ b/queue-5.10/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 +@@ -1132,7 +1132,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.10/ovl-fix-warning-in-ovl_create_real.patch b/queue-5.10/ovl-fix-warning-in-ovl_create_real.patch new file mode 100644 index 00000000000..8c8e8225ebc --- /dev/null +++ b/queue-5.10/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 +@@ -519,6 +519,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 +@@ -743,10 +743,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.10/rcu-mark-accesses-to-rcu_state.n_force_qs.patch b/queue-5.10/rcu-mark-accesses-to-rcu_state.n_force_qs.patch new file mode 100644 index 00000000000..33dada51560 --- /dev/null +++ b/queue-5.10/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 +@@ -1888,7 +1888,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); +@@ -2530,7 +2530,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; + +@@ -2876,10 +2876,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); + } + } +@@ -3986,7 +3986,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; + if (rcu_segcblist_empty(&rdp->cblist) && /* No early-boot CBs? */ + !rcu_segcblist_is_offloaded(&rdp->cblist)) diff --git a/queue-5.10/scsi-scsi_debug-don-t-call-kcalloc-if-size-arg-is-zero.patch b/queue-5.10/scsi-scsi_debug-don-t-call-kcalloc-if-size-arg-is-zero.patch new file mode 100644 index 00000000000..e6340cc4d0b --- /dev/null +++ b/queue-5.10/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 +@@ -4238,6 +4238,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); +@@ -4301,6 +4303,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.10/scsi-scsi_debug-fix-type-in-min_t-to-avoid-stack-oob.patch b/queue-5.10/scsi-scsi_debug-fix-type-in-min_t-to-avoid-stack-oob.patch new file mode 100644 index 00000000000..bb1bbea0e76 --- /dev/null +++ b/queue-5.10/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 +@@ -1188,7 +1188,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; + } + +@@ -1561,7 +1561,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); +@@ -1584,7 +1585,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; + +@@ -1675,9 +1677,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; + } +@@ -1713,7 +1715,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; + } +@@ -1728,8 +1730,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)); +@@ -1773,7 +1775,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) +@@ -2311,7 +2313,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]; +@@ -2467,7 +2470,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 +@@ -2582,7 +2585,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; + +@@ -2652,9 +2656,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) +@@ -4409,7 +4413,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.10/scsi-scsi_debug-sanity-check-block-descriptor-length-in-resp_mode_select.patch b/queue-5.10/scsi-scsi_debug-sanity-check-block-descriptor-length-in-resp_mode_select.patch new file mode 100644 index 00000000000..cda7bc97359 --- /dev/null +++ b/queue-5.10/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 +@@ -2501,11 +2501,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.10/series b/queue-5.10/series index 13ca5510f1c..989a46a6910 100644 --- a/queue-5.10/series +++ b/queue-5.10/series @@ -84,3 +84,9 @@ input-touchscreen-avoid-bitwise-vs-logical-or-warning.patch arm-dts-imx6ull-pinfunc-fix-csi_data07__esai_tx0-pad-name.patch xsk-do-not-sleep-in-poll-when-need_wakeup-set.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 +rcu-mark-accesses-to-rcu_state.n_force_qs.patch -- 2.39.5