From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751369AbdFFExc (ORCPT ); Tue, 6 Jun 2017 00:53:32 -0400 Received: from mail-it0-f42.google.com ([209.85.214.42]:33601 "EHLO mail-it0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751327AbdFFExa (ORCPT ); Tue, 6 Jun 2017 00:53:30 -0400 From: Kees Cook To: Andrew Morton Cc: Kees Cook , Daniel Micay , Greg Kroah-Hartman , Wayne Porter , linux-kernel@vger.kernel.org Subject: [PATCH 5/6] staging/rts5208: Fix read overflow in memcpy Date: Mon, 5 Jun 2017 21:52:34 -0700 Message-Id: <1496724755-104187-6-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496724755-104187-1-git-send-email-keescook@chromium.org> References: <1496724755-104187-1-git-send-email-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Micay Noticed by FORTIFY_SOURCE, this swaps memcpy() for strncpy() to zero-value fill the end of the buffer instead of over-reading a string from .rodata. Signed-off-by: Daniel Micay [kees: wrote commit log] Signed-off-by: Kees Cook Cc: Greg Kroah-Hartman Cc: Wayne Porter --- drivers/staging/rts5208/rtsx_scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/rts5208/rtsx_scsi.c b/drivers/staging/rts5208/rtsx_scsi.c index a95c5de1aa00..36b5a11f21d2 100644 --- a/drivers/staging/rts5208/rtsx_scsi.c +++ b/drivers/staging/rts5208/rtsx_scsi.c @@ -536,7 +536,7 @@ static int inquiry(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (sendbytes > 8) { memcpy(buf, inquiry_buf, 8); - memcpy(buf + 8, inquiry_string, sendbytes - 8); + strncpy(buf + 8, inquiry_string, sendbytes - 8); if (pro_formatter_flag) { /* Additional Length */ buf[4] = 0x33; -- 2.7.4