linux/drivers/scsi/aacraid
Kees Cook 7ab734fc75 scsi: aacraid: Allocate cmd_priv with scsicmd
The aac_priv() helper assumes that the private cmd area immediately follows
struct scsi_cmnd. Allocate this space as part of scsicmd, else there is a
risk of heap overflow. Seen with GCC 13:

../drivers/scsi/aacraid/aachba.c: In function 'aac_probe_container':
../drivers/scsi/aacraid/aachba.c:841:26: warning: array subscript 16 is outside array bounds of 'void[392]' [-Warray-bounds=]
  841 |         status = cmd_priv->status;
      |                          ^~
In file included from ../include/linux/resource_ext.h:11,
                 from ../include/linux/pci.h:40,
                 from ../drivers/scsi/aacraid/aachba.c:22:
In function 'kmalloc',
    inlined from 'kzalloc' at ../include/linux/slab.h:720:9,
    inlined from 'aac_probe_container' at ../drivers/scsi/aacraid/aachba.c:821:30:
../include/linux/slab.h:580:24: note: at offset 392 into object of size 392 allocated by 'kmalloc_trace'
  580 |                 return kmalloc_trace(
      |                        ^~~~~~~~~~~~~~
  581 |                                 kmalloc_caches[kmalloc_type(flags)][index],
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  582 |                                 flags, size);
      |                                 ~~~~~~~~~~~~

Fixes: 76a3451b64 ("scsi: aacraid: Move the SCSI pointer to private command data")
Link: https://lore.kernel.org/r/20230128000409.never.976-kees@kernel.org
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Himanshu Madhani <himanshu.madhani@oracle.com>
Cc: Adaptec OEM Raid Solutions <aacraid@microsemi.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
Cc: stable@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Vegard Nossum <vegard.nossum@oracle.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2023-02-08 18:49:48 -05:00
..
aachba.c scsi: aacraid: Allocate cmd_priv with scsicmd 2023-02-08 18:49:48 -05:00
aacraid.h scsi: aacraid: Fix undefined behavior due to shift overflowing the constant 2022-04-25 23:23:05 -04:00
commctrl.c scsi: aacraid: Fix incorrect spelling of aac_send_raw_srb() 2021-03-15 22:14:51 -04:00
comminit.c blk-mq: Drop 'reserved' arg of busy_tag_iter_fn 2022-07-06 06:33:53 -06:00
commsup.c scsi: aacraid: Use scsi_cmd_to_rq() instead of scsi_cmnd.request 2021-08-11 22:25:38 -04:00
dpcsup.c
linit.c blk-mq: Drop 'reserved' arg of busy_tag_iter_fn 2022-07-06 06:33:53 -06:00
Makefile
nark.c scsi: aacraid: Add missing description for 'dev' 2020-07-24 22:09:58 -04:00
rkt.c scsi: aacraid: Add missing description for 'dev' 2020-07-24 22:09:57 -04:00
rx.c scsi: aacraid: Fix misspelling of _aac_rx_init() 2021-03-15 22:14:53 -04:00
sa.c scsi: aacraid: Add descriptions for missing parameters 2020-07-24 22:09:57 -04:00
src.c scsi: aacraid: Add descriptions for missing parameters 2020-07-24 22:09:58 -04:00