Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1910938pxb; Thu, 16 Sep 2021 20:00:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXcDTtQmxEwtBx09VrCdMJFT1scffpTCSoT06AY+fhVkBTV2+bWt6Zz6h3NKxGffiNOUTD X-Received: by 2002:a02:6405:: with SMTP id t5mr6894655jac.136.1631847635260; Thu, 16 Sep 2021 20:00:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631847635; cv=none; d=google.com; s=arc-20160816; b=ao/dSqYDzu22ULvhf03EisWkT4YnYXYbp7Ob2wQu2eVh/Xp6X/nIuryM8kSp4dCnLU DBdA5DTso3AeN9sMP4cc9wWUJOpJHsXcpIX3KNZCXr0yA1gAlyKOv/6rKOEjAmQLhcxN ZYwtP1X3PBspE3BJQL/kDZuVFD0lMNNC2h6vnVnwi+GxiGOG+q6I5CYNOjx1pwy0c6wl oBz5gU+SwbSXxEB7lWW6HaREQZzYOqgUC2sK7OlrhQ73JxyjwxfXXhljAWem82bjfPzj J7+kvALhZhdXrGhX/OrgSTVxMrFoUFnmuslULE3CDXcatjVZv4EUfCgEypzf3SEybnZX lk1Q== 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=fCJYJ+okAZ3cuulBPopzWbxi0M4pK6oYg50ROQoiG8A=; b=ec4rpngPAM3r2nGFYvp9dcsrdtbxZbO/fDxXbdXL2SLPpptt0Q6FJ9F6NbDzb/4GSL Sru4mrar5mEukc1UbgxN+R/xBlmtp53al6e6f8g7yM8mTALMhxAu5OA7zKxbuKqdjs51 /Zs3XerhSyxjN8stVWAwz4RYJIHPRzyZePNG1/R3plgrA+NZnYJ/bAteuQmA9ykiIR4u TCfX0dZHlu+yFhfdMfglT0J5hLZB6qRzK8pRGGwaJPQs9aCD2YjaKWhJSHbSzbqotoaO G7QWiHkinrc4SCfnhtAej4Bm8PNqC0vq/rgSdaBU9GBe7mhczZCdy/FK8C/kIh36Qhid J8JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aTNqd+yZ; 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 n3si4161684ilj.23.2021.09.16.20.00.24; Thu, 16 Sep 2021 20:00:35 -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=aTNqd+yZ; 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 S1348191AbhIPR1j (ORCPT + 99 others); Thu, 16 Sep 2021 13:27:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:51938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347032AbhIPQ4u (ORCPT ); Thu, 16 Sep 2021 12:56:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4A5EF61381; Thu, 16 Sep 2021 16:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631809880; bh=wT3iu+1KsIblfmC2Xxu1rpoOWJc5iroPFIXC6zv3PRM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aTNqd+yZRFwBpPTxPDSv1YDluD3Ql2Ew0VlpZrI5rBCMNSnrYHS7wnoyAEdWthrcW eEZcFrm/5ZeJyIZnkNJqhZckG7Hxr54c2wzmQR47CLO5ZNB4icApdN/8QF3xtbTqyF Rihh+xeJNwOuLC/zRjKxaJyT4Y1YoVuDkjqGc1zA= 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 5.13 285/380] staging: rts5208: Fix get_ms_information() heap buffer size Date: Thu, 16 Sep 2021 18:00:42 +0200 Message-Id: <20210916155813.771281329@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155803.966362085@linuxfoundation.org> References: <20210916155803.966362085@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 1deb74112ad4..11d9d9155eef 100644 --- a/drivers/staging/rts5208/rtsx_scsi.c +++ b/drivers/staging/rts5208/rtsx_scsi.c @@ -2802,10 +2802,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; } @@ -2855,11 +2855,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