Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1116777rwi; Wed, 19 Oct 2022 06:58:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4pUuSKTQcO48DuWnyMyM86aP62DCFvIeIRHJUpQvmiOm0xJw3sZwt41El/T0dQ6FGnNLtn X-Received: by 2002:aa7:dd01:0:b0:45c:6453:d22e with SMTP id i1-20020aa7dd01000000b0045c6453d22emr7556788edv.120.1666187921055; Wed, 19 Oct 2022 06:58:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666187921; cv=none; d=google.com; s=arc-20160816; b=xEe+ShxSp0SsNTxZrOEHMw6EEkrrvk4fCKgJkTu6eWQDjR3yLqyRoKET5YIcqlKxFo R9CY0Az/nPrKfPa4Wny78JhG/7TmCnUTr7oPM/e7rvnhY83Fkk+lHVV+Mb9jeD+91WyI C+pqczx9YAfTKtLSIUz0cd9ut+onMET3HG5KNm6FlCxAIx1uksPR5Skr7RCbaFwXeONM g+IXcTZ32h3ww1tA13wyssr2DrK7oW4lOIxjIcqelYk55BhJnkvhbK2v01L+cV8g9Jl8 z2kGm1kBDLvNDoSELShqbkMEMVMwciojObcxm/bYNqVIuqbKLCNlVraPHhOJPFhl9rG+ AYMg== 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=wUpc0JklphYRHszPs+nf74a1yV1xUtuilsi3x8LRcT42nWUz0ex+iabCdH/feq7F9D Golcmz6H0MwLeY5MxgqudpOWnqueYgetxusLzaEuc/UGyi1SKHXGcQA/8bVgTBehynPt SBhyMuVkDr4EcHmJy17hLtmRew0B3FuDp5k4rhPLHhCibOoMpIlR0V7PlQB1aJqJIgHR zuWbPwSSXQZikSJ6r3tlXjDBlyMh6vLFsQy4gDfmUHJUxOPkpn0AoZFgnT97DUmm4Dwk UiXe1AXYBP4Fr+efy7ZTUNjQnvjRT7XWM82pfB/2G68qJsM26Bf4rQYA72GPq3uM/L2d 2TDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A3ziCNs7; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ce12-20020a170906b24c00b007819684b56fsi12244615ejb.225.2022.10.19.06.58.14; Wed, 19 Oct 2022 06:58:41 -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=A3ziCNs7; 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 S233525AbiJSNrf (ORCPT + 99 others); Wed, 19 Oct 2022 09:47:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233314AbiJSNqQ (ORCPT ); Wed, 19 Oct 2022 09:46:16 -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 67516172527; Wed, 19 Oct 2022 06:32:12 -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 3D6F1B82461; Wed, 19 Oct 2022 09:01:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF861C433C1; Wed, 19 Oct 2022 09:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170065; bh=vpqfbiunWovxa5YCg5882NV1JJiUtyPwMIje/6zZPJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A3ziCNs7eFbbSyGyu0W9JNISyxAor8yDDfq7eHJfLTBIz9fNuwLDuCGRlqcTf5aa6 iuikciD41aljedEDcZeftuVKzrLO6g+lqx0M9qOaerZ7hqGj3kdZlybv5GHyA0b07Z 9VnpDsHgxHcNL1M3Qmt2TIBV+ToOSuk1xZEuogio= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Sasha Levin Subject: [PATCH 6.0 512/862] usb: gadget: f_fs: stricter integer overflow checks Date: Wed, 19 Oct 2022 10:29:59 +0200 Message-Id: <20221019083312.610349805@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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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); -- 2.35.1