From patchwork Wed Oct 19 08:30:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4780 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp215756wrs; Wed, 19 Oct 2022 02:16:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5nvynJpp0ylypattXXb/BcbqBICDCa7GS+gPEWTPVAmkTca4Lh6soLzEDWz8HLzoHDUvIb X-Received: by 2002:a17:907:a40f:b0:790:540c:b6e3 with SMTP id sg15-20020a170907a40f00b00790540cb6e3mr5904723ejc.41.1666170995193; Wed, 19 Oct 2022 02:16:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666170995; cv=none; d=google.com; s=arc-20160816; b=dQ6fvh6C/eha9BSw+fCcAAqwVF301DXIG+xpwBG9ttMy9gFkwM7b1HxYQXi4V5ISKc b8SKzJ9IHLqUkmsjeagGbZ3l/2MBWs6HdNB1pHP1IkqqCvxK0dfUB8cLSJFjcgnOsHyh vGQJc17ojK7C/BmnYBMjUuHLjovkChoZNyCzQpUhdsnPUqxZ0cEND0LqMs6RhZI3QdHt /JK03w85rMn+15tBH1IHWYrrIlprQYneqs3tna091SAuRhACP8lqhN8WAxWU30/d8p3W 9ZmBooC/zFsmBQeJbVz5s6/kS0j6BlqFfJamDb7K/VVisnOLApG0KlGskNTHttxKTrsh PBlg== 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=gtCFeexjlwRhakT+0LL2q9Zf7acWfPhVCCp5QrlWvps=; b=oFNTNYKU+BCuUxyIO+VdlD61odeyxZ2MHyJHF/aajJykTKdyNGcK652q1SVmbVXsIn UCTtUS0ODAwE47tQ2mJBnGIR0saIltC/46aJ0rOC2v2eYg1GHg0kKSPCHwzpyDBAXlC/ CKuxrQqwEPooQPOvHRHxOGyWFmLDFTPGIPHToJP36thDZdu+Y2daCrL282tgvcUy53GB UsYKAP13P+MyHdCy2ig86wKrg5rUAOzhaKzO2UrsULpb5qhAvd68oMGxmmqcXu+z3E45 2HGOvVDBcCPHrlK8GqxFX4N5Y7wVaHG9RpL2viaQnkYet61D6RBAf+F1LL467pCBF3Iu JsTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=foGm2pLt; 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 i16-20020a50fc10000000b0045c26758001si12087349edr.539.2022.10.19.02.16.10; Wed, 19 Oct 2022 02:16:35 -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=foGm2pLt; 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 S233050AbiJSJNn (ORCPT + 99 others); Wed, 19 Oct 2022 05:13:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232762AbiJSJLF (ORCPT ); Wed, 19 Oct 2022 05:11:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56CC44F3BD; Wed, 19 Oct 2022 02:02: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 dfw.source.kernel.org (Postfix) with ESMTPS id 27D0F6174B; Wed, 19 Oct 2022 09:02:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36041C433D7; Wed, 19 Oct 2022 09:02:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170130; bh=g4F35njtKClTm2AcWT7WheFUPbeErkcDnc/IAYofFMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=foGm2pLti9XZRJ4JqtYG1VOz/T7vokLw2J0+2eGLBrd/0XBkUcjSw36R/jhHxIeAF 80R2s9MxOQQ8iXIZek2QqztJXQh5UYs6WqJfn2jy/VEDdNuTPKiFSkFpBvK1wWIVM6 R9A/gR+IIVFuKGQnXY3QGFLrdHkzpk4TFSg0/+sc= 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 6.0 521/862] remoteproc: Harden rproc_handle_vdev() against integer overflow Date: Wed, 19 Oct 2022 10:30:08 +0200 Message-Id: <20221019083313.006320760@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747106917451960258?= X-GMAIL-MSGID: =?utf-8?q?1747106917451960258?= 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 e5279ed9a8d7..4fc5ce2187ac 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -520,12 +520,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; }