mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-24 12:15:35 +07:00
14e3062fb1
Avoid that scsi_show_rq() triggers a NULL pointer dereference if called
after sd_uninit_command(). Swap the NULL pointer assignment and the
mempool_free() call in sd_uninit_command() to make it less likely that
scsi_show_rq() triggers a use-after-free. Note: even with these changes
scsi_show_rq() can trigger a use-after-free but that's a lesser evil
than e.g. suppressing debug information for T10 PI Type 2 commands
completely. This patch fixes the following oops:
BUG: unable to handle kernel NULL pointer dereference at (null)
IP: scsi_format_opcode_name+0x1a/0x1c0
CPU: 1 PID: 1881 Comm: cat Not tainted 4.14.0-rc2.blk_mq_io_hang+ #516
Call Trace:
__scsi_format_command+0x27/0xc0
scsi_show_rq+0x5c/0xc0
__blk_mq_debugfs_rq_show+0x116/0x130
blk_mq_debugfs_rq_show+0xe/0x10
seq_read+0xfe/0x3b0
full_proxy_read+0x54/0x90
__vfs_read+0x37/0x160
vfs_read+0x96/0x130
SyS_read+0x55/0xc0
entry_SYSCALL_64_fastpath+0x1a/0xa5
[mkp: added Type 2]
Fixes: 0eebd005dd
("scsi: Implement blk_mq_ops.show_rq()")
Reported-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: James E.J. Bottomley <jejb@linux.vnet.ibm.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Cc: stable@vger.kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
19 lines
604 B
C
19 lines
604 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/seq_file.h>
|
|
#include <scsi/scsi_cmnd.h>
|
|
#include <scsi/scsi_dbg.h>
|
|
#include "scsi_debugfs.h"
|
|
|
|
void scsi_show_rq(struct seq_file *m, struct request *rq)
|
|
{
|
|
struct scsi_cmnd *cmd = container_of(scsi_req(rq), typeof(*cmd), req);
|
|
int msecs = jiffies_to_msecs(jiffies - cmd->jiffies_at_alloc);
|
|
const u8 *const cdb = READ_ONCE(cmd->cmnd);
|
|
char buf[80] = "(?)";
|
|
|
|
if (cdb)
|
|
__scsi_format_command(buf, sizeof(buf), cdb, cmd->cmd_len);
|
|
seq_printf(m, ", .cmd=%s, .retries=%d, allocated %d.%03d s ago", buf,
|
|
cmd->retries, msecs / 1000, msecs % 1000);
|
|
}
|