Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2564798lkm; Mon, 20 Sep 2021 18:50:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxw6bORfOmGgVrUPmcUPfdcO036/V7cQAcaljlfxZpJMyS+k543HTLK4bIJiUUu20ApykCY X-Received: by 2002:a50:aa9c:: with SMTP id q28mr32003394edc.199.1632189041470; Mon, 20 Sep 2021 18:50:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189041; cv=none; d=google.com; s=arc-20160816; b=LBOL9GHpjPonNFKdmWKlPzaJ72xPTDIa2D8ZChdTsSj3MOt8OuiDKNIHZPZ07b6NPq INSbRpdRA2mpUyLZ54+tjwM2yJQijFQKiIiDmgVlIGVQI31QvMsBLFGxg1qf4huQWVY/ GiXatTozTdDfbzsS1kw2wpzjDfrdPHAqdgMeCR0ZE+tnrJentUQAyU6V6ZDaoriKc3VK x70owDdta2IFI6+2P1M0YrLEZVvgP161MWn3UZ/X+SIrQ2yoW9gbvcZeGVJ3pXOGzCK0 Urrw6mAhaOg9J5k0XuXOLC/IRptlq913dg/MYklQkPbNY5jh9l4YELcfuNLjHAMtGBnK 7InQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NcVSC3n23EUdTzkj/D2ccLK9ymnLh2aVw/qTd7u8u5s=; b=gbmT1ZJ+M/met8fgHM/F0K7pd0wPgPBSb07DROQTu8BVH7w3AoZa0mlF1jq0CYrCcQ Z/8VSxdP+2HehkCxqC5tobOt9VKTKTsXTRpIYuunIHt3KptoQbzxDzU0dV+lA8gsj9J4 O1mlSYEQfDlA/KALPZt/pg1e7+elPIdOc6MRfc9ylSV/F6a86vKA3uZl5GBgQRLEDTfz 7H4lc6pj+IJap2wDyXAWgsRcpk49/KP/xjw3Bekmln/KU7NjGIMVQYwoHWVIZ4lyQyzB kkMkMzunLkfG/IUGyXHWecYxjXNbodmI19y18AS69ZktJxHJbsYEKQbVfu1RXpbym5bs C1nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NhDinvsj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b25si20415034ejl.528.2021.09.20.18.50.18; Mon, 20 Sep 2021 18:50:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NhDinvsj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350279AbhITSAq (ORCPT + 99 others); Mon, 20 Sep 2021 14:00:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:53072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354729AbhITRvI (ORCPT ); Mon, 20 Sep 2021 13:51:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B8C5961352; Mon, 20 Sep 2021 17:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157940; bh=A5j40hBeOa+S/CWU9wfHang6QqKX1n9X4A6eC31b2Do=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NhDinvsjHpLCai+YwHWO0WQmOInh93rl3OX/KHO9Sn0ZhKUa5HbFGcpzXJc24k8bY uqXJ0fnxBih9BcxgSoFcIm2V5/3jPjxy3Q8kbZ1kFuEgW+8T2NT5FquVyB0kr2qlUO TKHfVsvcXXUlyiwP5Q/RI4TfNA91UG9JgsdcW+Tc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, linux-staging@lists.linux.dev, Kees Cook , Sasha Levin Subject: [PATCH 4.19 222/293] staging: rts5208: Fix get_ms_information() heap buffer size Date: Mon, 20 Sep 2021 18:43:04 +0200 Message-Id: <20210920163940.986021614@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook [ Upstream commit cbe34165cc1b7d1110b268ba8b9f30843c941639 ] Fix buf allocation size (it needs to be 2 bytes larger). Found when __alloc_size() annotations were added to kmalloc() interfaces. In file included from ./include/linux/string.h:253, from ./include/linux/bitmap.h:10, from ./include/linux/cpumask.h:12, from ./arch/x86/include/asm/paravirt.h:17, from ./arch/x86/include/asm/irqflags.h:63, from ./include/linux/irqflags.h:16, from ./include/linux/rcupdate.h:26, from ./include/linux/rculist.h:11, from ./include/linux/pid.h:5, from ./include/linux/sched.h:14, from ./include/linux/blkdev.h:5, from drivers/staging/rts5208/rtsx_scsi.c:12: In function 'get_ms_information', inlined from 'ms_sp_cmnd' at drivers/staging/rts5208/rtsx_scsi.c:2877:12, inlined from 'rtsx_scsi_handler' at drivers/staging/rts5208/rtsx_scsi.c:3247:12: ./include/linux/fortify-string.h:54:29: warning: '__builtin_memcpy' forming offset [106, 107] is out of the bounds [0, 106] [-Warray-bounds] 54 | #define __underlying_memcpy __builtin_memcpy | ^ ./include/linux/fortify-string.h:417:2: note: in expansion of macro '__underlying_memcpy' 417 | __underlying_##op(p, q, __fortify_size); \ | ^~~~~~~~~~~~~ ./include/linux/fortify-string.h:463:26: note: in expansion of macro '__fortify_memcpy_chk' 463 | #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \ | ^~~~~~~~~~~~~~~~~~~~ drivers/staging/rts5208/rtsx_scsi.c:2851:3: note: in expansion of macro 'memcpy' 2851 | memcpy(buf + i, ms_card->raw_sys_info, 96); | ^~~~~~ Cc: Greg Kroah-Hartman Cc: linux-staging@lists.linux.dev Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20210818044252.1533634-1-keescook@chromium.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/rts5208/rtsx_scsi.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/staging/rts5208/rtsx_scsi.c b/drivers/staging/rts5208/rtsx_scsi.c index c9a6d97938f6..68889d082c3c 100644 --- a/drivers/staging/rts5208/rtsx_scsi.c +++ b/drivers/staging/rts5208/rtsx_scsi.c @@ -2841,10 +2841,10 @@ static int get_ms_information(struct scsi_cmnd *srb, struct rtsx_chip *chip) } if (dev_info_id == 0x15) { - buf_len = 0x3A; + buf_len = 0x3C; data_len = 0x3A; } else { - buf_len = 0x6A; + buf_len = 0x6C; data_len = 0x6A; } @@ -2895,11 +2895,7 @@ static int get_ms_information(struct scsi_cmnd *srb, struct rtsx_chip *chip) } rtsx_stor_set_xfer_buf(buf, buf_len, srb); - - if (dev_info_id == 0x15) - scsi_set_resid(srb, scsi_bufflen(srb) - 0x3C); - else - scsi_set_resid(srb, scsi_bufflen(srb) - 0x6C); + scsi_set_resid(srb, scsi_bufflen(srb) - buf_len); kfree(buf); return STATUS_SUCCESS; -- 2.30.2