Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scsi: sd: reject invalid pr_read_keys() num_keys values

The pr_read_keys() interface has a u32 num_keys parameter. The SCSI
PERSISTENT RESERVE IN command has a maximum READ KEYS service action
size of 65536 bytes. Reject num_keys values that are too large to fit
into the SCSI command.

This will become important when pr_read_keys() is exposed to untrusted
userspace via an <linux/pr.h> ioctl.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Stefan Hajnoczi and committed by
Jens Axboe
ab4fb1d8 48f22f80

+11 -1
+11 -1
drivers/scsi/sd.c
··· 1974 1974 { 1975 1975 int result, i, data_offset, num_copy_keys; 1976 1976 u32 num_keys = keys_info->num_keys; 1977 - int data_len = num_keys * 8 + 8; 1977 + int data_len; 1978 1978 u8 *data; 1979 + 1980 + /* 1981 + * Each reservation key takes 8 bytes and there is an 8-byte header 1982 + * before the reservation key list. The total size must fit into the 1983 + * 16-bit ALLOCATION LENGTH field. 1984 + */ 1985 + if (check_mul_overflow(num_keys, 8, &data_len) || 1986 + check_add_overflow(data_len, 8, &data_len) || 1987 + data_len > USHRT_MAX) 1988 + return -EINVAL; 1979 1989 1980 1990 data = kzalloc(data_len, GFP_KERNEL); 1981 1991 if (!data)