Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1484934pxj; Sat, 15 May 2021 16:55:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwq8dYO1aVUnqX1SFnED8SG8hU0ffcN47F203p3SLLOcR4opacPdLXg95knuC+RCvIzkByT X-Received: by 2002:a05:6602:718:: with SMTP id f24mr38505401iox.59.1621122946367; Sat, 15 May 2021 16:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621122946; cv=none; d=google.com; s=arc-20160816; b=On+rUEeh+kuEshY6avcGVBiuPmyFbLJF55MVWDPYQB8TeflqVYwjwVFycqCd0qlEUV 36lfASjvqvFkoFC1+4kjsc1RNi4mLC6iieoDqN++01wJCMSwhjH6T1bToV0LFaloo4JT 2eEyZPLMqPZYoFOksHLGfP5y6JUAVsjumT8l7ayDHXiMbv84Eqv4tv4HbeA7GNTsw/4F HLHgR6E2a75IzzfOrg8I0ykWIGgmM9Hp4NjuHv6ZusyrM4Y6Kx4Wwpg0XD3U9AKml6zu aDt+XDjiUdEaK6mCBFzp1weuePd4k4y4tuC+ws+IW9GXV3RDtW9TOwvDc7qQfxT5sf4k uyfA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=EF3L0in7NEzj6ElMl+BWTSS6pUJ9MpQEXPpc7xaKcWg=; b=Hhz/G0iqJ83tSTSN1XBxDGGP3AcJUiEQZAg6Pc3EFBgrYWFBVxW5kqTqJdGQbpBVm1 zx/JmwFzUiMZaAerGPejRf0RUEMpPNHyCLjOSHY0AkBk6EkmaykFLC0tgBKjahgL76ko tmwwF0zuzWNXpBBKJVdhdgrHLK3HISi1Pz0mp+m0+mc41iMmpcUgIczqhnx/+jrRXVQP cRxADNMRipKTkER6TQFQBZs+uCmrL7l2E9MCS3u4uo3HLaODOdv1cOsc5cyQ60Hv2r3b WHNuL1KbhNSUO16CJPElbUxV4BLLfvrD11mP+c7qpGE+iazGxw1o/2vIo7aEPMTueaPT mOUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x20si11922887jao.3.2021.05.15.16.55.29; Sat, 15 May 2021 16:55:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231494AbhEOOAa (ORCPT + 99 others); Sat, 15 May 2021 10:00:30 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:3700 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230210AbhEOOA0 (ORCPT ); Sat, 15 May 2021 10:00:26 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Fj6Pm3mJ3z16LXF; Sat, 15 May 2021 21:56:28 +0800 (CST) Received: from code-website.localdomain (10.175.127.227) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Sat, 15 May 2021 21:59:02 +0800 From: Zheng Yejian To: CC: , , , , Subject: [PATCH 2/2] acct: Fix potential integer overflow in encode_comp_t() Date: Sat, 15 May 2021 22:06:31 +0800 Message-ID: <20210515140631.369106-3-zhengyejian1@huawei.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210515140631.369106-1-zhengyejian1@huawei.com> References: <20210515140631.369106-1-zhengyejian1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The integer overflow is descripted with following codes: > 317 static comp_t encode_comp_t(u64 value) > 318 { > 319 int exp, rnd; ...... > 341 exp <<= MANTSIZE; > 342 exp += value; > 343 return exp; > 344 } Currently comp_t is defined as type of '__u16', but the variable 'exp' is type of 'int', so overflow would happen when variable 'exp' in line 343 is greater than 65535. Signed-off-by: Zheng Yejian --- kernel/acct.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/acct.c b/kernel/acct.c index 9e143ed5b5d0..4182b92cf3df 100644 --- a/kernel/acct.c +++ b/kernel/acct.c @@ -331,6 +331,8 @@ static comp_t encode_comp_t(u64 value) exp++; } + if (exp > (((comp_t) ~0U) >> MANTSIZE)) + return (comp_t) ~0U; /* * Clean it up and polish it off. */ -- 2.17.1