Skip to content

Commit d857273

Browse files
Al Virogregkh
authored andcommitted
sg_write()/bsg_write() is not fit to be called under KERNEL_DS
commit 128394eff343fc6d2f32172f03e24829539c5835 upstream. 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. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7fb5a93 commit d857273

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

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
@@ -592,6 +592,9 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
592592
sg_io_hdr_t *hp;
593593
unsigned char cmnd[SG_MAX_CDB_SIZE];
594594

595+
if (unlikely(segment_eq(get_fs(), KERNEL_DS)))
596+
return -EINVAL;
597+
595598
if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp)))
596599
return -ENXIO;
597600
SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp,

0 commit comments

Comments
 (0)