Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp517452pxb; Thu, 9 Sep 2021 06:17:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlYLod+etSQOLvetYje3Gb5fhB8C662ZfFGO5BufwAVcr5zMNgM/VjyuhAjboZ5R9kvvjE X-Received: by 2002:a6b:a06:: with SMTP id z6mr2553235ioi.146.1631193435465; Thu, 09 Sep 2021 06:17:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631193435; cv=none; d=google.com; s=arc-20160816; b=y/8NlUG9mav4v5JUoNoZ490lwn4J11sbu6SJ/pEaJCr4kRKB/B8bE+3Gbvh7fvgtw/ hK3cbHpjXnjjerAAU1mCUPbXFEGwUtEtKuJjPePsl6JFF6hYVBYEd7YXdLZytA5fsaOM Gkhl8cMf1rHE1HKTpArfenOghOGZo2v2qkCdDR9LYaChqZBsKrRExlMd65hWRfFRhXBC QXgeujhUPPRo8dFlOGR5UrEGnlx5htg6vHieUejLrqVi0Z4R62G1c1dzcQ3rnOEhbBWO RSyi3k+ACaqvSOxjES7ouR0ATTgZBVMmxxubzLgvBQmV/2LDOS17M/JMJWnAuP2bcvQ4 D1MA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vgu/zzxTdwe9685Mu7u8auLhHaE2MLOuyB1w76fS4WY=; b=CvCFfQZinyavwFzTcgLvsOxm8viAE7v0atUE3UgmPmGirums8UR7caZEg8sHGAbLgz uAu9qUQwshDMuteSICIpEUS1AqZHHNjjggw4xug7XtU1+EUmxIuTyF4X5gc5LwEfMJfG AQS9PsSQ3SOQv7voxKkeWEf4xlWD976LhyQGPHv++fNOaflBEKH8jLqzDcfl1YKbnWls MQ4aaC2esgx4/tF4DLDNgXGMkVZsg15srnVKLYgTaq94pVd+aSadnmzQtIjML7T0hbO+ /xmM1NCh9xVNsIw/PxjZhHmewT+iU432mtNUkOvnvfq+oCltyQSt1CwDylhcw7WC70FM /dcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="YjI1kk8/"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r131si1627919ior.19.2021.09.09.06.16.58; Thu, 09 Sep 2021 06:17:15 -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=@kernel.org header.s=k20201202 header.b="YjI1kk8/"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357352AbhIINPC (ORCPT + 99 others); Thu, 9 Sep 2021 09:15:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:43480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355398AbhIINDk (ORCPT ); Thu, 9 Sep 2021 09:03:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7BA946329C; Thu, 9 Sep 2021 11:59:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188791; bh=GRhJGOE30nH8bfCQst7rI7i6KlEzDKNJgdHyLz+qXcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YjI1kk8/vnpazE1FdIi2n4kIDCrBTUkTnyarez3hihIUuoMnC4NLCBYqae/r46l5H yHNEx5lJFrHvii35jq+vtiKuV+zT5gk/WCE1yLb0vgGxdsJBlCk8flchAzEV9oKBz8 cw3SWBmtyGqu0c61jeeFm4Qx0JNvF0+cgNiT2JsrLYJ7vqI7Pl5vZFScX/Y1cunuYw tKLCLeB2iKdYVlU1TP07ZiI5/EmWoW3CgrMqKaiMIzoT1Mc1r/AoVFhhWYvEYBZB1+ Qe14h3hqt1Xk9peDh3h3G88WJlKrgwtop+cf2srHZ43s6CfR2HowgsrzGWhf6GdAZm YPGV9hxuTm1cw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kees Cook , Greg Kroah-Hartman , linux-staging@lists.linux.dev, Sasha Levin Subject: [PATCH AUTOSEL 4.14 40/59] staging: rts5208: Fix get_ms_information() heap buffer size Date: Thu, 9 Sep 2021 07:58:41 -0400 Message-Id: <20210909115900.149795-40-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909115900.149795-1-sashal@kernel.org> References: <20210909115900.149795-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 a401b13f5f5e..c46ac0e5e852 100644 --- a/drivers/staging/rts5208/rtsx_scsi.c +++ b/drivers/staging/rts5208/rtsx_scsi.c @@ -3026,10 +3026,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; } @@ -3081,11 +3081,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