From patchwork Sat Oct 22 07:25:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7575 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1106206wrr; Sat, 22 Oct 2022 01:37:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM70Pe0jZyW81TtZPRcUZP7S1KI1L3H3bnS3I6Zy9/HWXoYo4g6KK2P06SWx8qbFZ5shcMHo X-Received: by 2002:a17:907:2ceb:b0:78d:b765:c50d with SMTP id hz11-20020a1709072ceb00b0078db765c50dmr19075888ejc.73.1666427836220; Sat, 22 Oct 2022 01:37:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427836; cv=none; d=google.com; s=arc-20160816; b=arQQYxbIESYzX5/NiPaVV2uEcvSXcFWvBmbdd6+sN1tzewMneQmexhDjgtXuobo+HZ qhha5UMxhew4u/DaeJDk4uTRGcfAH74F3K/JMMO4I5QRx7oJxmbyPNGMLEfoUV2MDR3T qd1/m6xSi84nVGVfxXd6cNi1abaZrL1n3cpTgCVG/4LZPJ1jAOSOyzWf+1LqsaDlvVEG bSA/rlnmExOeXED0vVz6aRXheKIEKs81Uzd2RJN4SIYD3uu1cUlHfyfmjHr24oT1leNF DqxnCRwn8pe5QKkOIaN8QAzL4j0gbZmvaU3tfrACo2UXi7WOBRIFBp7fT6pt+Sbb4kDK VEnw== 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=3OXnaUtfx85+PCDsFTyfPyDgLo+UACYInkWFlZ9sq9Y=; b=lFtfjZR6hB/1Z9CBThvIRfxoM03SO/mvySDHd7r5diK5+kEJI0ombo/bx5IlfeybX1 7aMITtioti8VIi++f9dq1rBhFtAZt6MB2L1t8k0iueBkbTjI8bgY0f/+E0ulDtR2IewR gCmlPlSoUJVYhiYdQ71NBMNDQ4OyZCJ/58UAmwryT6qiiICR0Jp0Bn9DaTRm2NC3Q1QH Wqr7iA/F/uTOqTWn3kONkzZMmOd/8h0cDAvBZ8reHxXOgEVoqFTGiBkTyJc2j9ugC4wn qe0oleWoIAYHVYOFGeoqADfAaQccUJe0q6ppOqvOzAa0w0Bc6wR4CoWl52DixQ/UZzPM VUng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HR5RZGFM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg37-20020a170907972500b00791a37e665esi11557577ejc.10.2022.10.22.01.36.49; Sat, 22 Oct 2022 01:37:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HR5RZGFM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234028AbiJVIcY (ORCPT + 99 others); Sat, 22 Oct 2022 04:32:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234024AbiJVI3O (ORCPT ); Sat, 22 Oct 2022 04:29:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D63F512D01; Sat, 22 Oct 2022 01:01:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4177CB82E03; Sat, 22 Oct 2022 07:53:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76F97C433D6; Sat, 22 Oct 2022 07:53:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425219; bh=b7nk5n+pn5dwuzcRGHt+Ga4aNSHt99eeLerkhnMnA88=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HR5RZGFMilMd19a7QviZsj8gTcu4W8Q3KGEFK9dn9YW9ZDaDgA6pl4AxhgHnLBITp 4eHl8Ew9YchOSYcYSq+cDe96eumNKjB1FbpYoumIg1jXHRDY+VlpEd/pcPVcF95lS+ G6Lc9nd72l44KNsNdOvee6+akIVrRl+WhHdMRpVI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , "Gustavo A. R. Silva" , Mukesh Ojha , Mathieu Poirier , Sasha Levin Subject: [PATCH 5.19 423/717] remoteproc: Harden rproc_handle_vdev() against integer overflow Date: Sat, 22 Oct 2022 09:25:02 +0200 Message-Id: <20221022072517.109421152@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747376234896113674?= X-GMAIL-MSGID: =?utf-8?q?1747376234896113674?= From: Dan Carpenter [ Upstream commit 7d7f8fe4e399519cc9ac68a475fec6d3a996341b ] The struct_size() macro protects against integer overflows but adding "+ rsc->config_len" introduces the risk of integer overflows again. Use size_add() to be safe. Fixes: c87846571587 ("remoteproc: use struct_size() helper") Signed-off-by: Dan Carpenter Reviewed-by: Gustavo A. R. Silva Reviewed-by: Mukesh Ojha Link: https://lore.kernel.org/r/YyMyoPoGOJUcEpZT@kili Signed-off-by: Mathieu Poirier Signed-off-by: Sasha Levin --- drivers/remoteproc/remoteproc_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 02a04ab34a23..9d86470df79b 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -518,12 +518,13 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr, struct fw_rsc_vdev *rsc = ptr; struct device *dev = &rproc->dev; struct rproc_vdev *rvdev; + size_t rsc_size; int i, ret; char name[16]; /* make sure resource isn't truncated */ - if (struct_size(rsc, vring, rsc->num_of_vrings) + rsc->config_len > - avail) { + rsc_size = struct_size(rsc, vring, rsc->num_of_vrings); + if (size_add(rsc_size, rsc->config_len) > avail) { dev_err(dev, "vdev rsc is truncated\n"); return -EINVAL; }