From 3aaca485f74b851a9ca92676b2a982b5eedf267b Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 13 Jun 2022 19:48:25 +0200 Subject: [PATCH] 5.18-stable patches added patches: iov_iter-fix-build-issue-due-to-possible-type-mis-match.patch --- ...issue-due-to-possible-type-mis-match.patch | 93 +++++++++++++++++++ queue-5.18/series | 1 + 2 files changed, 94 insertions(+) create mode 100644 queue-5.18/iov_iter-fix-build-issue-due-to-possible-type-mis-match.patch diff --git a/queue-5.18/iov_iter-fix-build-issue-due-to-possible-type-mis-match.patch b/queue-5.18/iov_iter-fix-build-issue-due-to-possible-type-mis-match.patch new file mode 100644 index 00000000000..0a6b41289cd --- /dev/null +++ b/queue-5.18/iov_iter-fix-build-issue-due-to-possible-type-mis-match.patch @@ -0,0 +1,93 @@ +From 1c27f1fc1549f0e470429f5497a76ad28a37f21a Mon Sep 17 00:00:00 2001 +From: Linus Torvalds +Date: Sat, 11 Jun 2022 10:30:20 -0700 +Subject: iov_iter: fix build issue due to possible type mis-match + +From: Linus Torvalds + +commit 1c27f1fc1549f0e470429f5497a76ad28a37f21a upstream. + +Commit 6c77676645ad ("iov_iter: Fix iter_xarray_get_pages{,_alloc}()") +introduced a problem on some 32-bit architectures (at least arm, xtensa, +csky,sparc and mips), that have a 'size_t' that is 'unsigned int'. + +The reason is that we now do + + min(nr * PAGE_SIZE - offset, maxsize); + +where 'nr' and 'offset' and both 'unsigned int', and PAGE_SIZE is +'unsigned long'. As a result, the normal C type rules means that the +first argument to 'min()' ends up being 'unsigned long'. + +In contrast, 'maxsize' is of type 'size_t'. + +Now, 'size_t' and 'unsigned long' are always the same physical type in +the kernel, so you'd think this doesn't matter, and from an actual +arithmetic standpoint it doesn't. + +But on 32-bit architectures 'size_t' is commonly 'unsigned int', even if +it could also be 'unsigned long'. In that situation, both are unsigned +32-bit types, but they are not the *same* type. + +And as a result 'min()' will complain about the distinct types (ignore +the "pointer types" part of the error message: that's an artifact of the +way we have made 'min()' check types for being the same): + + lib/iov_iter.c: In function 'iter_xarray_get_pages': + include/linux/minmax.h:20:35: error: comparison of distinct pointer types lacks a cast [-Werror] + 20 | (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) + | ^~ + lib/iov_iter.c:1464:16: note: in expansion of macro 'min' + 1464 | return min(nr * PAGE_SIZE - offset, maxsize); + | ^~~ + +This was not visible on 64-bit architectures (where we always define +'size_t' to be 'unsigned long'). + +Force these cases to use 'min_t(size_t, x, y)' to make the type explicit +and avoid the issue. + +[ Nit-picky note: technically 'size_t' doesn't have to match 'unsigned + long' arithmetically. We've certainly historically seen environments + with 16-bit address spaces and 32-bit 'unsigned long'. + + Similarly, even in 64-bit modern environments, 'size_t' could be its + own type distinct from 'unsigned long', even if it were arithmetically + identical. + + So the above type commentary is only really descriptive of the kernel + environment, not some kind of universal truth for the kinds of wild + and crazy situations that are allowed by the C standard ] + +Reported-by: Sudip Mukherjee +Link: https://lore.kernel.org/all/YqRyL2sIqQNDfky2@debian/ +Cc: Jeff Layton +Cc: David Howells +Cc: Al Viro +Signed-off-by: Linus Torvalds +Cc: Guenter Roeck +Signed-off-by: Greg Kroah-Hartman +--- + lib/iov_iter.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +--- a/lib/iov_iter.c ++++ b/lib/iov_iter.c +@@ -1461,7 +1461,7 @@ static ssize_t iter_xarray_get_pages(str + if (nr == 0) + return 0; + +- return min(nr * PAGE_SIZE - offset, maxsize); ++ return min_t(size_t, nr * PAGE_SIZE - offset, maxsize); + } + + /* must be done on non-empty ITER_IOVEC one */ +@@ -1625,7 +1625,7 @@ static ssize_t iter_xarray_get_pages_all + if (nr == 0) + return 0; + +- return min(nr * PAGE_SIZE - offset, maxsize); ++ return min_t(size_t, nr * PAGE_SIZE - offset, maxsize); + } + + ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, diff --git a/queue-5.18/series b/queue-5.18/series index a4b3fe3a596..471a0d4f907 100644 --- a/queue-5.18/series +++ b/queue-5.18/series @@ -337,3 +337,4 @@ random-mark-bootloader-randomness-code-as-__init.patch random-account-for-arch-randomness-in-bits.patch md-raid0-ignore-raid0-layout-if-the-second-zone-has-only-one-device.patch zonefs-fix-handling-of-explicit_open-option-on-mount.patch +iov_iter-fix-build-issue-due-to-possible-type-mis-match.patch -- 2.47.3