Skip to content

Commit 128394e

Browse files
author
Al Viro
committed
sg_write()/bsg_write() is not fit to be called under KERNEL_DS
Both damn things interpret userland pointers embedded into the payload; worse, they are actually traversing those. Leaving aside the bad API design, this is very much _not_ safe to call with KERNEL_DS. Bail out early if that happens. Cc: stable@vger.kernel.org Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent f698ccc commit 128394e

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

block/bsg.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,9 @@ bsg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
655655

656656
dprintk("%s: write %Zd bytes\n", bd->name, count);
657657

658+
if (unlikely(segment_eq(get_fs(), KERNEL_DS)))
659+
return -EINVAL;
660+
658661
bsg_set_block(bd, file);
659662

660663
bytes_written = 0;

drivers/scsi/sg.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
581581
sg_io_hdr_t *hp;
582582
unsigned char cmnd[SG_MAX_CDB_SIZE];
583583

584+
if (unlikely(segment_eq(get_fs(), KERNEL_DS)))
585+
return -EINVAL;
586+
584587
if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp)))
585588
return -ENXIO;
586589
SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp,

0 commit comments

Comments
 (0)