Skip to content

Commit b9be19e

Browse files
auldpYuryNorov
authored andcommitted
drivers/base: Fix unsigned comparison to -1 in CPUMAP_FILE_MAX_BYTES
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. Cc: Greg Kroah-Hartman <[email protected]> Cc: "Rafael J. Wysocki" <[email protected]> Cc: Yury Norov <[email protected]> Cc: [email protected] Cc: feng xiangjun <[email protected]> Fixes: 7ee951a ("drivers/base: fix userspace break from using bin_attributes for cpumap and cpulist") Reported-by: feng xiangjun <[email protected]> Signed-off-by: Phil Auld <[email protected]> Signed-off-by: Yury Norov <[email protected]>
1 parent 7e18e42 commit b9be19e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

include/linux/cpumask.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,9 +1127,10 @@ cpumap_print_list_to_buf(char *buf, const struct cpumask *mask,
11271127
* cover a worst-case of every other cpu being on one of two nodes for a
11281128
* very large NR_CPUS.
11291129
*
1130-
* Use PAGE_SIZE as a minimum for smaller configurations.
1130+
* Use PAGE_SIZE as a minimum for smaller configurations while avoiding
1131+
* unsigned comparison to -1.
11311132
*/
1132-
#define CPUMAP_FILE_MAX_BYTES ((((NR_CPUS * 9)/32 - 1) > PAGE_SIZE) \
1133+
#define CPUMAP_FILE_MAX_BYTES (((NR_CPUS * 9)/32 > PAGE_SIZE) \
11331134
? (NR_CPUS * 9)/32 - 1 : PAGE_SIZE)
11341135
#define CPULIST_FILE_MAX_BYTES (((NR_CPUS * 7)/2 > PAGE_SIZE) ? (NR_CPUS * 7)/2 : PAGE_SIZE)
11351136

0 commit comments

Comments
 (0)