From 47ec6d5d156e13d01abb9f4a43859e56dc85be4a Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sun, 21 Mar 2021 13:13:33 +0100 Subject: [PATCH] 5.11-stable patches added patches: cifs-fix-allocation-size-on-newly-created-files.patch cifs-warn-and-fail-if-trying-to-use-rootfs-without-the-config-option.patch risc-v-fix-out-of-bounds-accesses-in-init_resources.patch riscv-correct-sparsemem-configuration.patch --- ...location-size-on-newly-created-files.patch | 58 +++++++++++++++++++ ...use-rootfs-without-the-config-option.patch | 35 +++++++++++ ...of-bounds-accesses-in-init_resources.patch | 40 +++++++++++++ ...iscv-correct-sparsemem-configuration.patch | 42 ++++++++++++++ queue-5.11/series | 4 ++ 5 files changed, 179 insertions(+) create mode 100644 queue-5.11/cifs-fix-allocation-size-on-newly-created-files.patch create mode 100644 queue-5.11/cifs-warn-and-fail-if-trying-to-use-rootfs-without-the-config-option.patch create mode 100644 queue-5.11/risc-v-fix-out-of-bounds-accesses-in-init_resources.patch create mode 100644 queue-5.11/riscv-correct-sparsemem-configuration.patch diff --git a/queue-5.11/cifs-fix-allocation-size-on-newly-created-files.patch b/queue-5.11/cifs-fix-allocation-size-on-newly-created-files.patch new file mode 100644 index 00000000000..008d981f910 --- /dev/null +++ b/queue-5.11/cifs-fix-allocation-size-on-newly-created-files.patch @@ -0,0 +1,58 @@ +From 65af8f0166f4d15e61c63db498ec7981acdd897f Mon Sep 17 00:00:00 2001 +From: Steve French +Date: Fri, 19 Mar 2021 00:05:48 -0500 +Subject: cifs: fix allocation size on newly created files + +From: Steve French + +commit 65af8f0166f4d15e61c63db498ec7981acdd897f upstream. + +Applications that create and extend and write to a file do not +expect to see 0 allocation size. When file is extended, +set its allocation size to a plausible value until we have a +chance to query the server for it. When the file is cached +this will prevent showing an impossible number of allocated +blocks (like 0). This fixes e.g. xfstests 614 which does + + 1) create a file and set its size to 64K + 2) mmap write 64K to the file + 3) stat -c %b for the file (to query the number of allocated blocks) + +It was failing because we returned 0 blocks. Even though we would +return the correct cached file size, we returned an impossible +allocation size. + +Signed-off-by: Steve French +CC: +Reviewed-by: Aurelien Aptel +Signed-off-by: Greg Kroah-Hartman +--- + fs/cifs/inode.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +--- a/fs/cifs/inode.c ++++ b/fs/cifs/inode.c +@@ -2383,7 +2383,7 @@ int cifs_getattr(const struct path *path + * We need to be sure that all dirty pages are written and the server + * has actual ctime, mtime and file length. + */ +- if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE)) && ++ if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE | STATX_BLOCKS)) && + !CIFS_CACHE_READ(CIFS_I(inode)) && + inode->i_mapping && inode->i_mapping->nrpages != 0) { + rc = filemap_fdatawait(inode->i_mapping); +@@ -2573,6 +2573,14 @@ set_size_out: + if (rc == 0) { + cifsInode->server_eof = attrs->ia_size; + cifs_setsize(inode, attrs->ia_size); ++ /* ++ * i_blocks is not related to (i_size / i_blksize), but instead ++ * 512 byte (2**9) size is required for calculating num blocks. ++ * Until we can query the server for actual allocation size, ++ * this is best estimate we have for blocks allocated for a file ++ * Number of blocks must be rounded up so size 1 is not 0 blocks ++ */ ++ inode->i_blocks = (512 - 1 + attrs->ia_size) >> 9; + + /* + * The man page of truncate says if the size changed, diff --git a/queue-5.11/cifs-warn-and-fail-if-trying-to-use-rootfs-without-the-config-option.patch b/queue-5.11/cifs-warn-and-fail-if-trying-to-use-rootfs-without-the-config-option.patch new file mode 100644 index 00000000000..384227176a8 --- /dev/null +++ b/queue-5.11/cifs-warn-and-fail-if-trying-to-use-rootfs-without-the-config-option.patch @@ -0,0 +1,35 @@ +From af3ef3b1031634724a3763606695ebcd113d782b Mon Sep 17 00:00:00 2001 +From: Aurelien Aptel +Date: Thu, 18 Mar 2021 19:17:10 +0100 +Subject: cifs: warn and fail if trying to use rootfs without the config option + +From: Aurelien Aptel + +commit af3ef3b1031634724a3763606695ebcd113d782b upstream. + +If CONFIG_CIFS_ROOT is not set, rootfs mount option is invalid + +Signed-off-by: Aurelien Aptel +CC: # v5.11 +Signed-off-by: Steve French +Signed-off-by: Greg Kroah-Hartman +--- + fs/cifs/fs_context.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +--- a/fs/cifs/fs_context.c ++++ b/fs/cifs/fs_context.c +@@ -1175,9 +1175,11 @@ static int smb3_fs_context_parse_param(s + pr_warn_once("Witness protocol support is experimental\n"); + break; + case Opt_rootfs: +-#ifdef CONFIG_CIFS_ROOT +- ctx->rootfs = true; ++#ifndef CONFIG_CIFS_ROOT ++ cifs_dbg(VFS, "rootfs support requires CONFIG_CIFS_ROOT config option\n"); ++ goto cifs_parse_mount_err; + #endif ++ ctx->rootfs = true; + break; + case Opt_posixpaths: + if (result.negated) diff --git a/queue-5.11/risc-v-fix-out-of-bounds-accesses-in-init_resources.patch b/queue-5.11/risc-v-fix-out-of-bounds-accesses-in-init_resources.patch new file mode 100644 index 00000000000..d0af565edf2 --- /dev/null +++ b/queue-5.11/risc-v-fix-out-of-bounds-accesses-in-init_resources.patch @@ -0,0 +1,40 @@ +From ce989f1472ae350e844b10c880b22543168fbc92 Mon Sep 17 00:00:00 2001 +From: Geert Uytterhoeven +Date: Fri, 12 Mar 2021 16:46:34 +0100 +Subject: RISC-V: Fix out-of-bounds accesses in init_resources() + +From: Geert Uytterhoeven + +commit ce989f1472ae350e844b10c880b22543168fbc92 upstream. + +init_resources() allocates an array of resources, based on the current +total number of memory regions and reserved memory regions. However, +allocating this array using memblock_alloc() might increase the number +of reserved memory regions. If that happens, populating the array later +based on the new number of regions will cause out-of-bounds writes +beyond the end of the allocated array. + +Fix this by allocating one more entry, which may or may not be used. + +Fixes: 797f0375dd2ef5cd ("RISC-V: Do not allocate memblock while iterating reserved memblocks") +Signed-off-by: Geert Uytterhoeven +Reviewed-by: Atish Patra +Cc: stable@vger.kernel.org +Signed-off-by: Palmer Dabbelt +Signed-off-by: Greg Kroah-Hartman +--- + arch/riscv/kernel/setup.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +--- a/arch/riscv/kernel/setup.c ++++ b/arch/riscv/kernel/setup.c +@@ -147,7 +147,8 @@ static void __init init_resources(void) + bss_res.end = __pa_symbol(__bss_stop) - 1; + bss_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; + +- mem_res_sz = (memblock.memory.cnt + memblock.reserved.cnt) * sizeof(*mem_res); ++ /* + 1 as memblock_alloc() might increase memblock.reserved.cnt */ ++ mem_res_sz = (memblock.memory.cnt + memblock.reserved.cnt + 1) * sizeof(*mem_res); + mem_res = memblock_alloc(mem_res_sz, SMP_CACHE_BYTES); + if (!mem_res) + panic("%s: Failed to allocate %zu bytes\n", __func__, mem_res_sz); diff --git a/queue-5.11/riscv-correct-sparsemem-configuration.patch b/queue-5.11/riscv-correct-sparsemem-configuration.patch new file mode 100644 index 00000000000..a41fd411224 --- /dev/null +++ b/queue-5.11/riscv-correct-sparsemem-configuration.patch @@ -0,0 +1,42 @@ +From a5406a7ff56e63376c210b06072aa0ef23473366 Mon Sep 17 00:00:00 2001 +From: Kefeng Wang +Date: Mon, 15 Mar 2021 20:03:07 +0800 +Subject: riscv: Correct SPARSEMEM configuration + +From: Kefeng Wang + +commit a5406a7ff56e63376c210b06072aa0ef23473366 upstream. + +There are two issues for RV32, +1) if use FLATMEM, it is useless to enable SPARSEMEM_STATIC. +2) if use SPARSMEM, both SPARSEMEM_VMEMMAP and SPARSEMEM_STATIC is enabled. + +Fixes: d95f1a542c3d ("RISC-V: Implement sparsemem") +Signed-off-by: Kefeng Wang +Cc: stable@vger.kernel.org +Signed-off-by: Palmer Dabbelt +Signed-off-by: Greg Kroah-Hartman +--- + arch/riscv/Kconfig | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +--- a/arch/riscv/Kconfig ++++ b/arch/riscv/Kconfig +@@ -87,7 +87,6 @@ config RISCV + select PCI_MSI if PCI + select RISCV_INTC + select RISCV_TIMER if RISCV_SBI +- select SPARSEMEM_STATIC if 32BIT + select SPARSE_IRQ + select SYSCTL_EXCEPTION_TRACE + select THREAD_INFO_IN_TASK +@@ -148,7 +147,8 @@ config ARCH_FLATMEM_ENABLE + config ARCH_SPARSEMEM_ENABLE + def_bool y + depends on MMU +- select SPARSEMEM_VMEMMAP_ENABLE ++ select SPARSEMEM_STATIC if 32BIT && SPARSMEM ++ select SPARSEMEM_VMEMMAP_ENABLE if 64BIT + + config ARCH_SELECT_MEMORY_MODEL + def_bool ARCH_SPARSEMEM_ENABLE diff --git a/queue-5.11/series b/queue-5.11/series index f2ee7403172..e15ec4d5d50 100644 --- a/queue-5.11/series +++ b/queue-5.11/series @@ -57,3 +57,7 @@ pstore-fix-warning-in-pstore_kill_sb.patch io_uring-ensure-that-sqpoll-thread-is-started-for-exit.patch net-qrtr-fix-__netdev_alloc_skb-call.patch kbuild-fix-linux-version.h-for-empty-sublevel-or-patchlevel-again.patch +cifs-warn-and-fail-if-trying-to-use-rootfs-without-the-config-option.patch +cifs-fix-allocation-size-on-newly-created-files.patch +risc-v-fix-out-of-bounds-accesses-in-init_resources.patch +riscv-correct-sparsemem-configuration.patch -- 2.47.3