From: akpm@linux-foundation.org Subject: [patch 7/7] hptiop: avoid buffer overflow when returning sense data Date: Tue, 16 Oct 2007 14:28:24 -0700 Message-ID: <200710162128.l9GLSORo018187@imap1.linux-foundation.org> Return-path: Received: from smtp2.linux-foundation.org ([207.189.120.14]:44779 "EHLO smtp2.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760124AbXJPV3K (ORCPT ); Tue, 16 Oct 2007 17:29:10 -0400 Sender: linux-scsi-owner@vger.kernel.org List-Id: linux-scsi@vger.kernel.org To: James.Bottomley@steeleye.com Cc: linux-scsi@vger.kernel.org, akpm@linux-foundation.org, linux@highpoint-tech.com, stable@kernel.org From: HighPoint Linux Team avoid buffer overflow when returning sense data. With current adapter firmware the driver is working but future firmware updates may return sense data larger than 96 bytes, causing overflow on scp->sense_buffer and a kernel crash. This fix should be backported to earlier kernels. Signed-off-by: HighPoint Linux Team Cc: James Bottomley Cc: Signed-off-by: Andrew Morton --- drivers/scsi/hptiop.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff -puN drivers/scsi/hptiop.c~hptiop-avoid-buffer-overflow-when-returning-sense-data drivers/scsi/hptiop.c --- a/drivers/scsi/hptiop.c~hptiop-avoid-buffer-overflow-when-returning-sense-data +++ a/drivers/scsi/hptiop.c @@ -375,8 +375,9 @@ static void hptiop_host_request_callback scp->result = SAM_STAT_CHECK_CONDITION; memset(&scp->sense_buffer, 0, sizeof(scp->sense_buffer)); - memcpy(&scp->sense_buffer, - &req->sg_list, le32_to_cpu(req->dataxfer_length)); + memcpy(&scp->sense_buffer, &req->sg_list, + min(sizeof(scp->sense_buffer), + le32_to_cpu(req->dataxfer_length))); break; default: _