From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82D521863 for ; Wed, 28 Dec 2022 15:50:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07211C433D2; Wed, 28 Dec 2022 15:50:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1672242630; bh=qR0vw+uQELOwhOUev5/wnJO2JEk9ykAYOvrnAJzGcKs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zzjiTwUlJofcP+2hmElmj+eGrLnXE6pJ4aJUY+v5i6JEISoB/rfAxcn2M3u7NeDic kk8ph/oRlUTIce6tRmH/GJ2gktjaa/AltB4VcKmwvVKr8AAmgflwSGkHrSLoATqqIG KQKBlDIPu4G4/P9B/4zcGn29wCLyZ5xoqM7nD9jo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zheng Yejian , Hanjun Guo , Randy Dunlap , Vlastimil Babka , Zhang Jinhao , Andrew Morton , Sasha Levin Subject: [PATCH 5.15 627/731] acct: fix potential integer overflow in encode_comp_t() Date: Wed, 28 Dec 2022 15:42:14 +0100 Message-Id: <20221228144314.700154687@linuxfoundation.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221228144256.536395940@linuxfoundation.org> References: <20221228144256.536395940@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Zheng Yejian [ Upstream commit c5f31c655bcc01b6da53b836ac951c1556245305 ] 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. Link: https://lkml.kernel.org/r/20210515140631.369106-3-zhengyejian1@huawei.com Signed-off-by: Zheng Yejian Cc: Hanjun Guo Cc: Randy Dunlap Cc: Vlastimil Babka Cc: Zhang Jinhao Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- kernel/acct.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/acct.c b/kernel/acct.c index 23a7ab8e6cbc..2b5cc63eb295 100644 --- a/kernel/acct.c +++ b/kernel/acct.c @@ -331,6 +331,8 @@ static comp_t encode_comp_t(unsigned long value) exp++; } + if (exp > (((comp_t) ~0U) >> MANTSIZE)) + return (comp_t) ~0U; /* * Clean it up and polish it off. */ -- 2.35.1