From patchwork Sat Oct 22 07:24:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7455 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1098630wrr; Sat, 22 Oct 2022 01:11:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Y3xZdpDTJob8dMuIhKmv0BmXzZQ8e/nlHIZU7B5p9Zv0Om/Pdl45eKDTDzeHfF/nJqs8x X-Received: by 2002:a17:90a:bd01:b0:205:fa9c:1cfc with SMTP id y1-20020a17090abd0100b00205fa9c1cfcmr63254879pjr.116.1666426287014; Sat, 22 Oct 2022 01:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666426287; cv=none; d=google.com; s=arc-20160816; b=JFWSHo+mw2+5nqSvEqeGbNOBppG6U78xEuVYVOdTLcx4zdBSaIrRHIAP9e6aT3Wb6X ZEh11uIBjZ5yWpSRhesm7gRxoxlT6tYqbGZRW/9NLgjvKoa1tvhf6orVY8zTiIaZvZ7T fY4IjBbxh4aB/zPTPtGDRXIcj2ihVNpXfU6kGTm2Ha27WHgjU5SZTxEg/SE8B6QYPWFj XXYvGy4VyWLgfOtLk3lz0KlwRNI7VCsSiuezayXboNydhQNHEc3pkqHvt54bE2JG+Fmd E/LNnxwcUkVyU1NukkDaVczKlkZNAgBIEObILmWigj+8NjIcpHOo9xirNISNdSoQYjuP LUIA== 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=d1iHjBmYVefgoFKeQ96nLRwl9b6TLPErveY9hV1aOic=; b=MDkxBq6qeimKZ03ebdywzmkiKSP48AxTdVouhwRq23KFSR/7p1IKpn6ZaRM8OJQfXh gSl7uTKpWNNeZ3Ilr7LuHGoSX+rRI/uT4BD9ZEoX3znLJj9S9JFKSLsv5Pc9tLwrIpB4 GpBE7hmXyTMQP8SyFp1EZBewdbGcirQAiwObkztNXdGvrkYQn+R0RTYZcR0WS+QPeSrD d9pM9UCg6FljVcWI6bGDi5RMAtv0S4ZryMyGZleMaO+jtvBEgWf2xUrIvoijGe8jp/1i m4Mo7fIaZrDt0o2YcfOsqyzUPhWUN1sdCCYd8FoYz+WgTybITpxwWv0HAuXYfmW8opFs 05Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qFCPkfdk; 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 j12-20020a170903024c00b00179ec1d9eb4si34851600plh.112.2022.10.22.01.11.14; Sat, 22 Oct 2022 01:11:27 -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=qFCPkfdk; 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 S233005AbiJVIKU (ORCPT + 99 others); Sat, 22 Oct 2022 04:10:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232825AbiJVIGG (ORCPT ); Sat, 22 Oct 2022 04:06:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53F6E2D52D1; Sat, 22 Oct 2022 00:53:01 -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 E7A85B82DF1; Sat, 22 Oct 2022 07:52:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EE28C433D6; Sat, 22 Oct 2022 07:52:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425177; bh=vpqfbiunWovxa5YCg5882NV1JJiUtyPwMIje/6zZPJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qFCPkfdksa00J3N81jhrmrP3e5nabk09v5RII6n94OzKGIkm8WfSk/EHb19b8NJH0 MLoqsVMyfwfR4HzrE7lj52GuQMpuIIAqLdoNEjxzWpiIkJazRbp9gxax4ZHJcCi1Y6 mx7nYLg84M1eqbm3ZbGmHDTeEGurMWocOQiznRwc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Sasha Levin Subject: [PATCH 5.19 416/717] usb: gadget: f_fs: stricter integer overflow checks Date: Sat, 22 Oct 2022 09:24:55 +0200 Message-Id: <20221022072516.609281185@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?1747374610235459502?= X-GMAIL-MSGID: =?utf-8?q?1747374610235459502?= From: Dan Carpenter [ Upstream commit f57004b9d96755cd6a243b51c267be4016b4563c ] This from static analysis. The vla_item() takes a size and adds it to the total. It has a built in integer overflow check so if it encounters an integer overflow anywhere then it records the total as SIZE_MAX. However there is an issue here because the "lang_count*(needed_count+1)" multiplication can overflow. Technically the "lang_count + 1" addition could overflow too, but that would be detected and is harmless. Fix both using the new size_add() and size_mul() functions. Fixes: e6f3862fa1ec ("usb: gadget: FunctionFS: Remove VLAIS usage from gadget code") Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/YxDI3lMYomE7WCjn@kili Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/gadget/function/f_fs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index e0fa4b186ec6..36184a762527 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -2645,10 +2645,10 @@ static int __ffs_data_got_strings(struct ffs_data *ffs, unsigned i = 0; vla_group(d); vla_item(d, struct usb_gadget_strings *, stringtabs, - lang_count + 1); + size_add(lang_count, 1)); vla_item(d, struct usb_gadget_strings, stringtab, lang_count); vla_item(d, struct usb_string, strings, - lang_count*(needed_count+1)); + size_mul(lang_count, (needed_count + 1))); char *vlabuf = kmalloc(vla_group_size(d), GFP_KERNEL);