Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp793960rwb; Mon, 26 Sep 2022 06:04:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5SazxPbRhH0RVN6FVNzPgiLIHdrawFdWkDVklKMJvhxrMQNWq7o8UijASbpyOL4TJ/Kgl3 X-Received: by 2002:a17:90b:4c91:b0:202:a345:b771 with SMTP id my17-20020a17090b4c9100b00202a345b771mr36195973pjb.128.1664197440123; Mon, 26 Sep 2022 06:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664197440; cv=none; d=google.com; s=arc-20160816; b=h35U7yIb11ZGoO+8iCHEsAJ5voYLghc8dAc4U8evSXW2UdpPZxUQlNrR7XYF6MLfG4 I2dQ4Jgwy11zymw5FkELXkqaSPgpUW0f8rgd4kiUWWixRVPRET2iigc+4lY4c1E9sx1a q/gtsDlcxKecosp5HciErF8cU1vUkDJOPiCcnrrg4n5bTtknCPPNTkqYe7a+pqOpLZdt 6tRB0XEBQHsVtyq1XOAajdVgno9mqYOf+eT2uXb09YG159IHaZoYGvGbLRrty2wFxE6h NVx+gCNLcPRTRaX8RIkZQCdFQkKzsfg/COa8gFrEKFSz8TMpTXL29GTIRXjIDrw7mZjP Q1fA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=08ZPctaaf8cnak9VlQxXvINiJ+oZOgBStASA5iVYUQU=; b=zvvmskvjZ/H7Vp7sC4fhI18B/CXcKaEtH7XkIJzy824Bikre1erjrCp/EalkluBvy4 PJSKgjQmqYgFRQAhXxQ/q8kBtQYMV9U7mcr/k0zlcZM2xVsqtZyUGn5rHmfmlPj1oce1 HGm/pMqTzpQkVdcYTFW0J47/0tbD2Dy9gAR+JS718dlFJTo51U0/rQSAAeBKzYXN/Yph a/WsUXPJkyQsGzLxW3Yhqh6Kur4JXeHV/0ypQpcLeZxbgkob+rslda5SwKwc5zw054DT VZtADlZ55JzYJD9CqnPabQYJy/B8LI8ar9T4Lp0KiHqZZfXaUhyuz0gGlu+SMAS67OPE EGyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=voVb0GUg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s134-20020a632c8c000000b00438d54cf8c5si18722116pgs.759.2022.09.26.06.03.48; Mon, 26 Sep 2022 06:04:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=voVb0GUg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238124AbiIZLjV (ORCPT + 99 others); Mon, 26 Sep 2022 07:39:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238166AbiIZLhz (ORCPT ); Mon, 26 Sep 2022 07:37:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 096476EF1E; Mon, 26 Sep 2022 03:44:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A46DB60A36; Mon, 26 Sep 2022 10:42:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D444C433D6; Mon, 26 Sep 2022 10:42:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188940; bh=mXgQHzzbXk8scCA00EwPq4JkzV+JHFrkwHS/AwZf3bA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=voVb0GUgrFWRAaAZYimRjYLNyaLa4x3nJarP/VFWOG5wD1g0mnPNzL8QICKFWKclS c26zGfPk3xTkAgkc5gUrAUjc1so/fxW2TeK77pkd2RmrIC5ZV8W7VSPFsw3u5f18Ul 8x25iLXGpI/8FORe1fZb4/LuhGmgp+mfNAnrtSkw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Rafael J. Wysocki" , Yury Norov , feng xiangjun , Phil Auld Subject: [PATCH 5.19 021/207] drivers/base: Fix unsigned comparison to -1 in CPUMAP_FILE_MAX_BYTES Date: Mon, 26 Sep 2022 12:10:10 +0200 Message-Id: <20220926100807.421848068@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100806.522017616@linuxfoundation.org> References: <20220926100806.522017616@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Phil Auld commit d7f06bdd6ee87fbefa05af5f57361d85e7715b11 upstream. As PAGE_SIZE is unsigned long, -1 > PAGE_SIZE when NR_CPUS <= 3. This leads to very large file sizes: topology$ ls -l total 0 -r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 core_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 core_cpus_list -r--r--r-- 1 root root 4096 Sep 5 10:58 core_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 10:10 core_siblings -r--r--r-- 1 root root 4096 Sep 5 11:59 core_siblings_list -r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 die_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 die_cpus_list -r--r--r-- 1 root root 4096 Sep 5 11:59 die_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 11:59 package_cpus -r--r--r-- 1 root root 4096 Sep 5 11:59 package_cpus_list -r--r--r-- 1 root root 4096 Sep 5 10:58 physical_package_id -r--r--r-- 1 root root 18446744073709551615 Sep 5 10:10 thread_siblings -r--r--r-- 1 root root 4096 Sep 5 11:59 thread_siblings_list Adjust the inequality to catch the case when NR_CPUS is configured to a small value. Fixes: 7ee951acd31a ("drivers/base: fix userspace break from using bin_attributes for cpumap and cpulist") Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Cc: Yury Norov Cc: stable@vger.kernel.org Cc: feng xiangjun Reported-by: feng xiangjun Signed-off-by: Phil Auld Signed-off-by: Yury Norov Link: https://lore.kernel.org/r/20220906203542.1796629-1-pauld@redhat.com Signed-off-by: Greg Kroah-Hartman --- include/linux/cpumask.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -1083,9 +1083,10 @@ cpumap_print_list_to_buf(char *buf, cons * cover a worst-case of every other cpu being on one of two nodes for a * very large NR_CPUS. * - * Use PAGE_SIZE as a minimum for smaller configurations. + * Use PAGE_SIZE as a minimum for smaller configurations while avoiding + * unsigned comparison to -1. */ -#define CPUMAP_FILE_MAX_BYTES ((((NR_CPUS * 9)/32 - 1) > PAGE_SIZE) \ +#define CPUMAP_FILE_MAX_BYTES (((NR_CPUS * 9)/32 > PAGE_SIZE) \ ? (NR_CPUS * 9)/32 - 1 : PAGE_SIZE) #define CPULIST_FILE_MAX_BYTES (((NR_CPUS * 7)/2 > PAGE_SIZE) ? (NR_CPUS * 7)/2 : PAGE_SIZE)