Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp730512ybc; Sat, 16 Nov 2019 07:42:41 -0800 (PST) X-Google-Smtp-Source: APXvYqzJHFvKrPGDIRz4KY+I5gAH+l7zJc+kPDn0cgnmAEJZkio2fiNheY51XVVdbtUV8GHwi8p6 X-Received: by 2002:a17:906:f24d:: with SMTP id gy13mr10636595ejb.159.1573918960981; Sat, 16 Nov 2019 07:42:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573918960; cv=none; d=google.com; s=arc-20160816; b=aIoX7NudBbntli+HCPfq7aR5B/mjmMs9H5+Kcjn4iiheOnF7mFnAlqgmye7OGw+7xZ cUL/SATNZ75QbMavnz2VZ0pPt2uVITbR6GAF1UrofLZTFJQwa8QYpz21jE/RjtRelYdO KVq+bsF1RVI1QALBgPLWT3/gvqTYu6L0tH1qYG32Ge1PQgGn5EPlC23/YXL+LUigFNGx K1VoPie7v1xYnROTBbrt8FfZOnjKGN2bxmePow5CuC4eA9igIBfTn9EAjSuHEWoQxmA3 XUXTtkb0B0E0lhKCRBfNi8pybAbNEpF8lO2WkdJ5VwsyFSdnLVRiCFhsYn5qRCSLIWNE Up/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5iQKVBYjz4VJnYsR3qmu9AnchaD2twvI6QyKrXrAZA0=; b=Ho8kR9QGSq1Zc10YelZ9EhWU1KIGBgpt7OoZ8QlTXZnQGgFmq5zhXfaztRyfPWI/Sg PQ3uYQnYqWRlk7SzjmPqwQAWTgZcRBgCx4tW9FNQSH9I9KNCQ12otsrj2WOQoWC3nezp 3D3wx1ddoPTuAaNwMthuyikR5NFrsjY0UE0pVOu4VqyCKqXXEjJCAJK6YyG2FrHiveHT gvOOnLwz1QdYQILCicgG9Ys3i8qUdCEmEhAMWnPxfjMn8V5iTlxi9MU8F3MaKcNkT5k7 z1M1TnnqMlX5q0SEXtU9ciC4Qiq3jF3yM5OwlsXj+ZimdlvZrjWkaUbW27ySFaC15B38 f++g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="m/zZyBeL"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q12si8289934ejt.308.2019.11.16.07.42.16; Sat, 16 Nov 2019 07:42:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="m/zZyBeL"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727790AbfKPPlS (ORCPT + 99 others); Sat, 16 Nov 2019 10:41:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:44238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727597AbfKPPlQ (ORCPT ); Sat, 16 Nov 2019 10:41:16 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0903C2073B; Sat, 16 Nov 2019 15:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573918876; bh=Pc43BIn6SNyTHbunCDkaxTycG2IXVgbB1qnuJmsoS0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m/zZyBeLZVwu5hMwLCPl9TkSojEDipX9cZy+2bDAT2sUCzTmzFatsUcHbwI1PraAn N9RId0aZyw8SalpWJnD4qxdSXsLEn+XMs5lUtOpZrvfk4ZnagqeOb9QpWq58pYLpj5 HBtkNZwDWZtwWWHlnkMfT6lpTwBftmWCfkFqikYE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sergey Senozhatsky , Sergey Senozhatsky , Petr Mladek , Sasha Levin Subject: [PATCH AUTOSEL 4.19 004/237] printk: fix integer overflow in setup_log_buf() Date: Sat, 16 Nov 2019 10:37:19 -0500 Message-Id: <20191116154113.7417-4-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sergey Senozhatsky [ Upstream commit d2130e82e9454304e9b91ba9da551b5989af8c27 ] The way we calculate logbuf free space percentage overflows signed integer: int free; free = __LOG_BUF_LEN - log_next_idx; pr_info("early log buf free: %u(%u%%)\n", free, (free * 100) / __LOG_BUF_LEN); We support LOG_BUF_LEN of up to 1<<25 bytes. Since setup_log_buf() is called during early init, logbuf is mostly empty, so __LOG_BUF_LEN - log_next_idx is close to 1<<25. Thus when we multiply it by 100, we overflow signed integer value range: 100 is 2^6 + 2^5 + 2^2. Example, booting with LOG_BUF_LEN 1<<25 and log_buf_len=2G boot param: [ 0.075317] log_buf_len: -2147483648 bytes [ 0.075319] early log buf free: 33549896(-28%) Make "free" unsigned integer and use appropriate printk() specifier. Link: http://lkml.kernel.org/r/20181010113308.9337-1-sergey.senozhatsky@gmail.com To: Steven Rostedt Cc: linux-kernel@vger.kernel.org Cc: Sergey Senozhatsky Signed-off-by: Sergey Senozhatsky Signed-off-by: Petr Mladek Signed-off-by: Sasha Levin --- kernel/printk/printk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 9ee6016a19fc8..5bafd633b4027 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1098,7 +1098,7 @@ void __init setup_log_buf(int early) { unsigned long flags; char *new_log_buf; - int free; + unsigned int free; if (log_buf != __log_buf) return; -- 2.20.1