Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5974752rwp; Mon, 17 Jul 2023 12:34:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlEpOMwzIfadNmuuRlJ9yWCubIOSaDLmHwqe2yVrZZzW+Siw1qM/LFVeFjRYu9waVS5q9ww+ X-Received: by 2002:a17:902:d4ca:b0:1b8:936f:c346 with SMTP id o10-20020a170902d4ca00b001b8936fc346mr13758221plg.30.1689622483187; Mon, 17 Jul 2023 12:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689622483; cv=none; d=google.com; s=arc-20160816; b=SvEcgYSswGwgvWRpSFFIXGQwfmWhh12lUqtdOSN5QC5MrMODQyRvm+0QwbtXFucCr2 ZLBYWT71wwJ0DNPSvCqNKx3ogj5HHe5AagB1RNXoij9LDvQN7HGYU/kYF9HErAqnj2Zy fVX2CshnEPGhlwVp9yo/CPmvq7L6PTWt/nc8iI8WjJN6h0r7Akh7pshUK+rmICvheh8K SA+C+r+ajzLWFHDMEk/KLePhz3RBGGpJN8UplFUiVYIxYyBjJRdHvFpiLehlYzEXsBi6 Arg+TotSSpOvAhIANEv3zhYId/xnjPTB/vv4yrLEj5G81ujadZra7yhk7D2diBO6OpWm KZeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:subject:cc:to:from :message-id:date:content-transfer-encoding:mime-version :dkim-signature; bh=EJ3aIKkBg2G54NNELWnMYPYlB94RJkuv6aVbvAyKjNI=; fh=10hAJJLNaTJm5QRE4luG7/03OvxVtclrT/PrpeCLSTg=; b=ctetBy3zD+ORhs3HUoQYKyEx0QCvYxEUGxI2Pyi3juf8hIz/5N7OR5CpSZKKXjM5Jg qcw3aMa908s2GantHsGRJWuEDQ4fwaiUr4THqYB+7S1rxavEXKm9KmTI3/I/MaukZf9/ rOQ/GQ2rC73FWxZ1YDa5Mu55wmqYcex20PhTvO2NOg7KCFjqUdLbCPCfZi0/ext29JQS bwuxywsoiYWDxJG0nQpJfiFVgDgSkIgxfFPB4CuA4YUWfA0YU3zaN667FFU3KtA4JsRp +5PXQIuP0ft4TCAQBXqxgQ3KCN6kP2YIK+bGI6TpOYnAGznRnYxby+eOWS0PApmuv+N6 CEdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XuCqiqls; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j17-20020a170902da9100b001b54bdd6412si332515plx.396.2023.07.17.12.34.30; Mon, 17 Jul 2023 12:34:43 -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=@kernel.org header.s=k20201202 header.b=XuCqiqls; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231452AbjGQSzk (ORCPT + 99 others); Mon, 17 Jul 2023 14:55:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbjGQSzj (ORCPT ); Mon, 17 Jul 2023 14:55:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B63DAF; Mon, 17 Jul 2023 11:55:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C3AD0611F2; Mon, 17 Jul 2023 18:55:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA4E6C433C7; Mon, 17 Jul 2023 18:55:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689620137; bh=dAk9sfbRYrdRyd3dNaLS8GFgLcv5I6arjL3f8km5V5I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XuCqiqls/Fm9xg6gYy+ypyUZCJ/ubP1HJ+L1r0B+2EnftbpsJJWVarWcsGMPFm6md zVfOA1I69nFIzJJ36tlFfR+EI+8Gu0d7H2A7PW0waVt+zHPc+dMH9JFvQFtC8lEs0t znlKD55FBALVISOxK7TEwn7LMzd6y1nB5fkLAk5PyfDUQN2935bl2xB4OlT16Iz2eA sh+qKf5tTChVS7rPafUEd/X3KUj67uFsUBgKGYB3UtwggYwFBzClzKGnyHYhB5rIR4 1Z+q2SUmQ+JWiLtH8EUeXFHBXHEZu17uUqnpIxIZk1StD9FTh49FIxbYWFaW7/62fz RH/gGkI6km7qw== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 17 Jul 2023 18:55:32 +0000 Message-Id: From: "Jarkko Sakkinen" To: "Haitao Huang" , , , , , , "Zefan Li" , "Johannes Weiner" Cc: , , , , Subject: Re: [PATCH] cgroup/misc: Fix an overflow X-Mailer: aerc 0.14.0 References: <20230717184719.85523-1-haitao.huang@linux.intel.com> In-Reply-To: <20230717184719.85523-1-haitao.huang@linux.intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Mon Jul 17, 2023 at 6:47 PM UTC, Haitao Huang wrote: > The variable 'new_usage' in misc_cg_try_charge() may overflow if it > becomes above INT_MAX. This was observed when I implement the new SGX > EPC cgroup[1] as a misc cgroup and test on a platform with large SGX EPC > sizes. > > Change type of new_usage to long from int and check overflow. > > Fixes: a72232eabdfcf ("cgroup: Add misc cgroup controller") > Signed-off-by: Haitao Huang > > [1] https://lore.kernel.org/linux-sgx/20230712230202.47929-1-haitao.huang= @linux.intel.com/ > --- > kernel/cgroup/misc.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c > index fe3e8a0eb7ed..ff9f900981a3 100644 > --- a/kernel/cgroup/misc.c > +++ b/kernel/cgroup/misc.c > @@ -143,7 +143,7 @@ int misc_cg_try_charge(enum misc_res_type type, struc= t misc_cg *cg, > struct misc_cg *i, *j; > int ret; > struct misc_res *res; > - int new_usage; > + long new_usage; > =20 > if (!(valid_type(type) && cg && READ_ONCE(misc_res_capacity[type]))) > return -EINVAL; > @@ -153,10 +153,10 @@ int misc_cg_try_charge(enum misc_res_type type, str= uct misc_cg *cg, > =20 > for (i =3D cg; i; i =3D parent_misc(i)) { > res =3D &i->res[type]; > - This is extra noise in the patch, please remove the change. > new_usage =3D atomic_long_add_return(amount, &res->usage); > if (new_usage > READ_ONCE(res->max) || > - new_usage > READ_ONCE(misc_res_capacity[type])) { > + new_usage > READ_ONCE(misc_res_capacity[type]) || > + new_usage < 0) { > ret =3D -EBUSY; > goto err_charge; > } > --=20 > 2.25.1 BR, Jarkko