Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp131482pxb; Mon, 25 Oct 2021 05:21:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydz5Ol90NFJoK0v9E4qUak5+3ez1TE4CYqqNxpMKkiscxFNhIcJsC5QEhKB8x8nfll/ZTD X-Received: by 2002:a17:902:d703:b0:140:e3a:cc7e with SMTP id w3-20020a170902d70300b001400e3acc7emr15935916ply.65.1635164518592; Mon, 25 Oct 2021 05:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635164518; cv=none; d=google.com; s=arc-20160816; b=DdZ5kdqt3zEwDVq6ljMBykLze6yyzOeKVCUT2iUlXrMRUIqZCtaA0Y9LmGkA4A7lKv qKLYDc+qMSvkejXH8OnczBBJnrYE4rQ/Eijy03b6s0rQvc/iN/EmZC6UQv9nC+cYczSE by7s/Zk7yC07kJU+E4HpFvl2j3ytykjieYDkYM3ZtUJ+MIyfeLnITRRjQnt09wA05Ukp 72uFpDBei+NlFJ/CXBP09RFYom119Y0cebz5yZpyTb6jE1pi6wuU8WoEB+Q1uBYgiFRQ +ZW4/951UYczewTjzISFs6gttG5n3ZpZvUmFv4/nZ/65rOwx4YobbUHWWuPr5JLRiD7J Qsmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=gmmkuznyqJkKWmKLP99y8ObQ3X+N0nzREBtlF2gTZrg=; b=qFjkSpLuvv2dHwoLK2ciM8o4FW637Y92spxWwoPcgoEOdTl2ROBqG8OOVifKgetuPT aBqM5tsCFhP+ypbldndI7IG7m72uofWycHZ/hcmoUmwT/XRS4QsOwexziC3hJ2s1VVPY P094qIs24lZqXke8jKyL0CxfxNcAMgSVv3NqgYVEvNQGL6qZ3QULlAf96ymLt1vWfoQb l7XljoplqMTMVr4tdwzZ5NikJ/jA48bVJDJ8d0tZNY16OkhOuctqbqHlyQwjsPoggNc+ y6uxXIyu9s9d/ClInYPT7zzDq0FG82mX9rPnupOeUCm6qbcK+9GkJEN9fzAq+M5t8AxB KDWw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c8si25046611pgv.433.2021.10.25.05.21.43; Mon, 25 Oct 2021 05:21:58 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232905AbhJYMWy (ORCPT + 99 others); Mon, 25 Oct 2021 08:22:54 -0400 Received: from smtp21.cstnet.cn ([159.226.251.21]:51132 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232455AbhJYMWu (ORCPT ); Mon, 25 Oct 2021 08:22:50 -0400 Received: from localhost.localdomain (unknown [124.16.138.128]) by APP-01 (Coremail) with SMTP id qwCowAA3PAjaoHZhLBNQBQ--.18991S2; Mon, 25 Oct 2021 20:19:38 +0800 (CST) From: Jiasheng Jiang To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com Cc: linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH v2] sched: Fix implicit type conversion Date: Mon, 25 Oct 2021 12:19:37 +0000 Message-Id: <1635164377-2426740-1-git-send-email-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: qwCowAA3PAjaoHZhLBNQBQ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UjIFyTuYvjfU5rWrDUUUU X-Originating-IP: [124.16.138.128] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The variable 'n' is defined as ULONG. However in the cpumask_next(), it is used as INT. That is vulnerable and may cause overflow. For example, if the value of 'n' is (2^31 - 1), then it can pass the check ('n == 0') and ('n-- > 0'). Then in cpumask_next(), its value is (2^31 - 3). But it is implicit type conversed to int, its actual value is -3, which is illegal in the cpumask_next(). Therefore, it might be better to define 'n' as INT. Fixes: cb152ff ("sched: Fix /proc/sched_stat failure on very very large systems") Signed-off-by: Jiasheng Jiang --- kernel/sched/stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/stats.c b/kernel/sched/stats.c index 3f93fc3..6503d3a 100644 --- a/kernel/sched/stats.c +++ b/kernel/sched/stats.c @@ -82,7 +82,7 @@ static int show_schedstat(struct seq_file *seq, void *v) */ static void *schedstat_start(struct seq_file *file, loff_t *offset) { - unsigned long n = *offset; + int n = *offset; if (n == 0) return (void *) 1; -- 2.7.4