From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org,
syzbot+1ff6f9fcc3c35f1c72a95e26528c8e7e3276e4da@syzkaller.appspotmail.com,
Eric Biggers <ebiggers@google.com>, Tejun Heo <tj@kernel.org>
Subject: [PATCH 3.18 04/93] libata: fix length validation of ATAPI-relayed SCSI commands
Date: Fri, 6 Apr 2018 15:22:33 +0200 [thread overview]
Message-ID: <20180406084225.161489894@linuxfoundation.org> (raw)
In-Reply-To: <20180406084224.918716300@linuxfoundation.org>
3.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <ebiggers@google.com>
commit 058f58e235cbe03e923b30ea7c49995a46a8725f upstream.
syzkaller reported a crash in ata_bmdma_fill_sg() when writing to
/dev/sg1. The immediate cause was that the ATA command's scatterlist
was not DMA-mapped, which causes 'pi - 1' to underflow, resulting in a
write to 'qc->ap->bmdma_prd[0xffffffff]'.
Strangely though, the flag ATA_QCFLAG_DMAMAP was set in qc->flags. The
root cause is that when __ata_scsi_queuecmd() is preparing to relay a
SCSI command to an ATAPI device, it doesn't correctly validate the CDB
length before copying it into the 16-byte buffer 'cdb' in 'struct
ata_queued_cmd'. Namely, it validates the fixed CDB length expected
based on the SCSI opcode but not the actual CDB length, which can be
larger due to the use of the SG_NEXT_CMD_LEN ioctl. Since 'flags' is
the next member in ata_queued_cmd, a buffer overflow corrupts it.
Fix it by requiring that the actual CDB length be <= 16 (ATAPI_CDB_LEN).
[Really it seems the length should be required to be <= dev->cdb_len,
but the current behavior seems to have been intentionally introduced by
commit 607126c2a21c ("libata-scsi: be tolerant of 12-byte ATAPI commands
in 16-byte CDBs") to work around a userspace bug in mplayer. Probably
the workaround is no longer needed (mplayer was fixed in 2007), but
continuing to allow lengths to up 16 appears harmless for now.]
Here's a reproducer that works in QEMU when /dev/sg1 refers to the
CD-ROM drive that qemu-system-x86_64 creates by default:
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#define SG_NEXT_CMD_LEN 0x2283
int main()
{
char buf[53] = { [36] = 0x7e, [52] = 0x02 };
int fd = open("/dev/sg1", O_RDWR);
ioctl(fd, SG_NEXT_CMD_LEN, &(int){ 17 });
write(fd, buf, sizeof(buf));
}
The crash was:
BUG: unable to handle kernel paging request at ffff8cb97db37ffc
IP: ata_bmdma_fill_sg drivers/ata/libata-sff.c:2623 [inline]
IP: ata_bmdma_qc_prep+0xa4/0xc0 drivers/ata/libata-sff.c:2727
PGD fb6c067 P4D fb6c067 PUD 0
Oops: 0002 [#1] SMP
CPU: 1 PID: 150 Comm: syz_ata_bmdma_q Not tainted 4.15.0-next-20180202 #99
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-20171110_100015-anatol 04/01/2014
[...]
Call Trace:
ata_qc_issue+0x100/0x1d0 drivers/ata/libata-core.c:5421
ata_scsi_translate+0xc9/0x1a0 drivers/ata/libata-scsi.c:2024
__ata_scsi_queuecmd drivers/ata/libata-scsi.c:4326 [inline]
ata_scsi_queuecmd+0x8c/0x210 drivers/ata/libata-scsi.c:4375
scsi_dispatch_cmd+0xa2/0xe0 drivers/scsi/scsi_lib.c:1727
scsi_request_fn+0x24c/0x530 drivers/scsi/scsi_lib.c:1865
__blk_run_queue_uncond block/blk-core.c:412 [inline]
__blk_run_queue+0x3a/0x60 block/blk-core.c:432
blk_execute_rq_nowait+0x93/0xc0 block/blk-exec.c:78
sg_common_write.isra.7+0x272/0x5a0 drivers/scsi/sg.c:806
sg_write+0x1ef/0x340 drivers/scsi/sg.c:677
__vfs_write+0x31/0x160 fs/read_write.c:480
vfs_write+0xa7/0x160 fs/read_write.c:544
SYSC_write fs/read_write.c:589 [inline]
SyS_write+0x4d/0xc0 fs/read_write.c:581
do_syscall_64+0x5e/0x110 arch/x86/entry/common.c:287
entry_SYSCALL_64_after_hwframe+0x21/0x86
Fixes: 607126c2a21c ("libata-scsi: be tolerant of 12-byte ATAPI commands in 16-byte CDBs")
Reported-by: syzbot+1ff6f9fcc3c35f1c72a95e26528c8e7e3276e4da@syzkaller.appspotmail.com
Cc: <stable@vger.kernel.org> # v2.6.24+
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/ata/libata-scsi.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -3429,7 +3429,9 @@ static inline int __ata_scsi_queuecmd(st
if (likely((scsi_op != ATA_16) || !atapi_passthru16)) {
/* relay SCSI command to ATAPI device */
int len = COMMAND_SIZE(scsi_op);
- if (unlikely(len > scmd->cmd_len || len > dev->cdb_len))
+ if (unlikely(len > scmd->cmd_len ||
+ len > dev->cdb_len ||
+ scmd->cmd_len > ATAPI_CDB_LEN))
goto bad_cdb_len;
xlat_func = atapi_xlat;
next prev parent reply other threads:[~2018-04-06 13:25 UTC|newest]
Thread overview: 101+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-06 13:22 [PATCH 3.18 00/93] 3.18.103-stable review Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 01/93] ALSA: usb-audio: Fix parsing descriptor of UAC2 processing unit Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 02/93] ALSA: aloop: Sync stale timer before release Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 03/93] ALSA: aloop: Fix access to not-yet-ready substream via cable Greg Kroah-Hartman
2018-04-06 13:22 ` Greg Kroah-Hartman [this message]
2018-04-06 13:22 ` [PATCH 3.18 05/93] libata: remove WARN() for DMA or PIO command without data Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 06/93] libata: Apply NOLPM quirk to Crucial MX100 512GB SSDs Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 07/93] libata: disable LPM for Crucial BX100 SSD 500GB drive Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 08/93] libata: Enable queued TRIM for Samsung SSD 860 Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 09/93] libata: Apply NOLPM quirk to Crucial M500 480 and 960GB SSDs Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 10/93] libata: Make Crucial BX100 500GB LPM quirk apply to all firmware versions Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 11/93] libata: Modify quirks for MX100 to limit NCQ_TRIM quirk to MU01 version Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 12/93] drm: udl: Properly check framebuffer mmap offsets Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 13/93] brcmfmac: fix P2P_DEVICE ethernet address generation Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 14/93] tracing: probeevent: Fix to support minus offset from symbol Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 15/93] staging: ncpfs: memory corruption in ncp_read_kernel() Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 16/93] can: cc770: Fix stalls on rt-linux, remove redundant IRQ ack Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 17/93] can: cc770: Fix queue stall & dropped RTR reply Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 18/93] can: cc770: Fix use after free in cc770_tx_interrupt() Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 19/93] tty: vt: fix up tabstops properly Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 20/93] kvm/x86: fix icebp instruction handling Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 21/93] scsi: sg: dont return bogus Sg_requests Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 22/93] [PATCH] Revert "genirq: Use irqd_get_trigger_type to compare the trigger type for shared IRQs" Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 23/93] dccp: check sk for closed state in dccp_sendmsg() Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 24/93] ipv6: fix access to non-linear packet in ndisc_fill_redirect_hdr_option() Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 25/93] l2tp: do not accept arbitrary sockets Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 26/93] net: ethernet: arc: Fix a potential memory leak if an optional regulator is deferred Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 27/93] net/iucv: Free memory obtained by kzalloc Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 28/93] netlink: avoid a double skb free in genlmsg_mcast() Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 29/93] net: Only honor ifindex in IP_PKTINFO if non-0 Greg Kroah-Hartman
2018-04-06 13:22 ` [PATCH 3.18 30/93] skbuff: Fix not waking applications when errors are enqueued Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 31/93] team: Fix double free in error path Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 32/93] s390/qeth: free netdevice when removing a card Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 33/93] s390/qeth: when thread completes, wake up all waiters Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 34/93] s390/qeth: lock read device while queueing next buffer Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 35/93] s390/qeth: on channel error, reject further cmd requests Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 36/93] net: fec: Fix unbalanced PM runtime calls Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 37/93] mtd: jedec_probe: Fix crash in jedec_read_mfr() Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 38/93] ALSA: pcm: Use dma_bytes as size parameter in dma_mmap_coherent() Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 39/93] ALSA: pcm: potential uninitialized return values Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 40/93] perf/hwbp: Simplify the perf-hwbp code, fix documentation Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 41/93] partitions/msdos: Unable to mount UFS 44bsd partitions Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 42/93] usb: gadget: define free_ep_req as universal function Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 43/93] usb: gadget: change len to size_t on alloc_ep_req() Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 44/93] usb: gadget: fix usb_ep_align_maybe endianness and new usb_ep_align Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 45/93] usb: gadget: align buffer size when allocating for OUT endpoint Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 46/93] usb: gadget: f_hid: fix: Prevent accessing released memory Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 47/93] Revert "led: core: Fix brightness setting when setting delay_off=0" Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 48/93] xhci: Fix ring leak in failure path of xhci_alloc_virt_device() Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 49/93] kprobes/x86: Fix to set RWX bits correctly before releasing trampoline Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 50/93] xfrm_user: uncoditionally validate esn replay attribute struct Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 51/93] net: xfrm: use preempt-safe this_cpu_read() in ipcomp_alloc_tfms() Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 52/93] xfrm: Refuse to insert 32 bit userspace socket policies on 64 bit systems Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 53/93] netfilter: bridge: ebt_among: add more missing match size checks Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 54/93] netfilter: x_tables: add and use xt_check_proc_name Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 55/93] Bluetooth: Fix missing encryption refresh on Security Request Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 56/93] scsi: virtio_scsi: always read VPD pages for multiqueue too Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 57/93] media: v4l2-ioctl.c: dont copy back the result for -ENOTTY Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 58/93] [media] vb2: V4L2_BUF_FLAG_DONE is set after DQBUF Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 59/93] media: v4l2-compat-ioctl32.c: add missing VIDIOC_PREPARE_BUF Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 60/93] media: v4l2-compat-ioctl32.c: fix the indentation Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 61/93] media: v4l2-compat-ioctl32.c: move helper functions to __get/put_v4l2_format32 Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 62/93] media: v4l2-compat-ioctl32.c: avoid sizeof(type) Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 63/93] media: v4l2-compat-ioctl32.c: copy m.userptr in put_v4l2_plane32 Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 64/93] media: v4l2-compat-ioctl32.c: fix ctrl_is_pointer Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 65/93] media: v4l2-compat-ioctl32.c: make ctrl_is_pointer work for subdevs Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 66/93] media: v4l2-compat-ioctl32: Copy v4l2_window->global_alpha Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 67/93] media: v4l2-compat-ioctl32.c: copy clip list in put_v4l2_window32 Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 68/93] media: v4l2-compat-ioctl32.c: drop pr_info for unknown buffer type Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 69/93] media: v4l2-compat-ioctl32.c: dont copy back the result for certain errors Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 70/93] media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 71/93] media: v4l2-ctrls: fix sparse warning Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 72/93] media: media/v4l2-ctrls: volatiles should not generate CH_VALUE Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 73/93] media: v4l2-compat-ioctl32: use compat_u64 for video standard Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 74/93] media: v4l2-compat-ioctl32: initialize a reserved field Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 75/93] USB: serial: ftdi_sio: add RT Systems VX-8 cable Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 76/93] USB: serial: ftdi_sio: add support for Harman FirmwareHubEmulator Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 77/93] USB: serial: cp210x: add ELDAT Easywave RX09 id Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 78/93] mei: remove dev_err message on an unsupported ioctl Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 79/93] media: usbtv: prevent double free in error case Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 80/93] parport_pc: Add support for WCH CH382L PCI-E single parallel port card Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 81/93] crypto: ahash - Fix early termination in hash walk Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 82/93] crypto: x86/cast5-avx - fix ECB encryption when long sg follows short one Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 83/93] proc: revert /proc/<pid>/maps [stack:TID] annotation Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 84/93] fs/proc: Stop trying to report thread stacks Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 85/93] Input: i8042 - add Lenovo ThinkPad L460 to i8042 reset list Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 86/93] Input: i8042 - enable MUX on Sony VAIO VGN-CS series to fix touchpad Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 87/93] vt: change SGR 21 to follow the standards Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 88/93] Documentation: pinctrl: palmas: Add ti,palmas-powerhold-override property definition Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 89/93] ARM: dts: dra7: Add power hold and power controller properties to palmas Greg Kroah-Hartman
2018-04-06 13:23 ` [PATCH 3.18 90/93] md/raid10: reset the first at the end of loop Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 3.18 91/93] Revert "PCI/MSI: Stop disabling MSI/MSI-X in pci_device_shutdown()" Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 3.18 92/93] Revert "ARM: dts: omap3-n900: Fix the audio CODECs reset pin" Greg Kroah-Hartman
2018-04-06 13:24 ` [PATCH 3.18 93/93] Revert "ARM: dts: am335x-pepper: " Greg Kroah-Hartman
2018-04-06 19:11 ` [PATCH 3.18 00/93] 3.18.103-stable review Harsh Shandilya
2018-04-07 6:10 ` Greg Kroah-Hartman
2018-04-06 22:21 ` Shuah Khan
2018-04-08 14:07 ` Guenter Roeck
2018-04-08 15:13 ` Greg Kroah-Hartman
2018-04-08 20:26 ` Greg Kroah-Hartman
2018-04-09 8:13 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180406084225.161489894@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=ebiggers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+1ff6f9fcc3c35f1c72a95e26528c8e7e3276e4da@syzkaller.appspotmail.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).