All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: aha1740: Avoid over-read of sense buffer
@ 2021-06-16 21:24 Kees Cook
  2021-06-19  3:29 ` Martin K. Petersen
  0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2021-06-16 21:24 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Kees Cook, James E.J. Bottomley, linux-kernel, linux-scsi,
	linux-hardening

In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memcpy(), memmove(), and memset(), avoid
intentionally reading across neighboring array fields.

SCtmp->sense_buffer is 96 bytes, but ecbptr->sense is 14 bytes. Instead
of over-reading ecbptr->sense, copy only the actual contents and zero
pad the remaining bytes, avoiding potential over-reads.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/scsi/aha1740.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/aha1740.c b/drivers/scsi/aha1740.c
index 0dc831026e9e..39d8759fe558 100644
--- a/drivers/scsi/aha1740.c
+++ b/drivers/scsi/aha1740.c
@@ -267,8 +267,11 @@ static irqreturn_t aha1740_intr_handle(int irq, void *dev_id)
 			   guarantee that we will still have it in the
 			   cdb when we come back */
 			if ( (adapstat & G2INTST_MASK) == G2INTST_CCBERROR ) {
-				memcpy(SCtmp->sense_buffer, ecbptr->sense, 
-				       SCSI_SENSE_BUFFERSIZE);
+				memcpy_and_pad(SCtmp->sense_buffer,
+					       SCSI_SENSE_BUFFERSIZE,
+					       ecbptr->sense,
+					       sizeof(ecbptr->sense),
+					       0);
 				errstatus = aha1740_makecode(ecbptr->sense,ecbptr->status);
 			} else
 				errstatus = 0;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] scsi: aha1740: Avoid over-read of sense buffer
  2021-06-16 21:24 [PATCH] scsi: aha1740: Avoid over-read of sense buffer Kees Cook
@ 2021-06-19  3:29 ` Martin K. Petersen
  0 siblings, 0 replies; 2+ messages in thread
From: Martin K. Petersen @ 2021-06-19  3:29 UTC (permalink / raw)
  To: Kees Cook
  Cc: Martin K. Petersen, James E.J. Bottomley, linux-kernel,
	linux-scsi, linux-hardening


Kees,

> In preparation for FORTIFY_SOURCE performing compile-time and run-time
> field bounds checking for memcpy(), memmove(), and memset(), avoid
> intentionally reading across neighboring array fields.

Applied to 5.14/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-19  3:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-16 21:24 [PATCH] scsi: aha1740: Avoid over-read of sense buffer Kees Cook
2021-06-19  3:29 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.