Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp54517pxb; Mon, 25 Oct 2021 03:47:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynUaJDPhNFsp+uuMy1/qxVE3zPEs1XFYY8VJraszSbgpnun++DLJMvPufdve/miIkw99dm X-Received: by 2002:a63:b349:: with SMTP id x9mr12968025pgt.139.1635158870877; Mon, 25 Oct 2021 03:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635158870; cv=none; d=google.com; s=arc-20160816; b=bqeeDoxK16Gd704bBrNOS8KSaJ2cWgCuIooxGg01sB2FvfQ6DaB2qq89E01woWtr4p RlXqOH47FZtaeTyBHB2yZyN2pZDVtFbzxHm8cytkHGHmhzk2fH21i1Ud3EM/mU9eXMrJ HoY6i4LFTkiDppVIoCWhnzLw8ql5MKXiFvsBSKNlanM66HpjTth005rEEJmAiwVGP+H9 60VGI/zZYmwjT6TTIM6AqnbXwx+5xh8gNm4CM3+6U/LmdkcOt0258WuADOZ3oOReojWk bYCEYo9E2yAxBGskpI62/U6v+GobkbjsvUTpC4zrezBqNCPECi3CJMaR3k7I6YwyoXbw tr4Q== 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=JFQGufUp43fRRfTpmSP8JYneDR++M5mg+KlXKq8hAL0=; b=oUB61fjWkB1RZFCR1p18o9cSGfcOjqQXYeCk0X//WFmgihi2g3N0avXvbaiki43R/1 xyuuH3MJC7cxvlEJhMWJdMUOp7Qg6zdoBW740XIN+g89Ic3dg/gaVBmiKKYq3HQ5BR+N +kQqiKBYaI1Dp+7AhLfyyTwlOMxSDYyk9n9KeNyOFlpL1pWyH+gNoY5OPNJl2LnOY9St T7mHwCPcJO5Zk5O6gRhCoZead3ElvU5WmgXNk2hGIT6FhG8nOje4cuTeq1wfDW7aFEVn oJbQhyzNCzqN56dLzCM3AKXjxA7hLCYxeOrRBrTcv8C0u7Wcpi4gvEh7tQSu5/FEURej 1Bow== 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 s142si719730pgs.28.2021.10.25.03.47.38; Mon, 25 Oct 2021 03:47:50 -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 S231723AbhJYHeH (ORCPT + 99 others); Mon, 25 Oct 2021 03:34:07 -0400 Received: from smtp21.cstnet.cn ([159.226.251.21]:50562 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231710AbhJYHeF (ORCPT ); Mon, 25 Oct 2021 03:34:05 -0400 Received: from localhost.localdomain (unknown [124.16.138.128]) by APP-01 (Coremail) with SMTP id qwCowAAHoCBHXXZhWuRJBQ--.64178S2; Mon, 25 Oct 2021 15:31:19 +0800 (CST) From: Jiasheng Jiang To: viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH] seq_file: Fix potential addition overflow Date: Mon, 25 Oct 2021 07:31:18 +0000 Message-Id: <1635147078-2409190-1-git-send-email-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: qwCowAAHoCBHXXZhWuRJBQ--.64178S2 X-Coremail-Antispam: 1UD129KBjvdXoWrZF1rAw1ktFW8AryrWw4xtFb_yoWfXFc_ta 9avw1rGr42qa1vvF9rtr409rykAwn7tr4Yq34fX3sxtFWUKr43AF1DCr9xCr1fC395XF1D X34vvF90g3W5ujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbc8FF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s 1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0 cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8Jw ACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK67AK6r4xMxAI w28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr 4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxG rwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8Jw CI42IY6xAIw20EY4v20xvaj40_WFyUJVCq3wCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY 6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUekucDUUUU X-Originating-IP: [124.16.138.128] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After seq_hlist_start_percpu(), the value of &iter->li_cpu might be MAX_UINT. In that case, there will be addition overflow in the cpumask_next(). Therefore, it might be better to add the check before. Fixes: 0bc7738 ("seq_file: add seq_list_*_percpu helpers") Signed-off-by: Jiasheng Jiang --- fs/seq_file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/seq_file.c b/fs/seq_file.c index 5059248..f768c28 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -1105,6 +1105,9 @@ seq_hlist_next_percpu(void *v, struct hlist_head __percpu *head, if (node->next) return node->next; + if (*cpu >= nr_cpu_ids) + return NULL; + for (*cpu = cpumask_next(*cpu, cpu_possible_mask); *cpu < nr_cpu_ids; *cpu = cpumask_next(*cpu, cpu_possible_mask)) { struct hlist_head *bucket = per_cpu_ptr(head, *cpu); -- 2.7.4