--- /dev/null
+From 570b1cac477643cbf01a45fa5d018430a1fddbce Mon Sep 17 00:00:00 2001
+From: Xie Yongji <xieyongji@bytedance.com>
+Date: Tue, 26 Oct 2021 22:40:12 +0800
+Subject: block: Add a helper to validate the block size
+
+From: Xie Yongji <xieyongji@bytedance.com>
+
+commit 570b1cac477643cbf01a45fa5d018430a1fddbce upstream.
+
+There are some duplicated codes to validate the block
+size in block drivers. This limitation actually comes
+from block layer, so this patch tries to add a new block
+layer helper for that.
+
+Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
+Link: https://lore.kernel.org/r/20211026144015.188-2-xieyongji@bytedance.com
+Signed-off-by: Jens Axboe <axboe@kernel.dk>
+Signed-off-by: Tadeusz Struk <tadeusz.struk@linaro.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ include/linux/blkdev.h | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+--- a/include/linux/blkdev.h
++++ b/include/linux/blkdev.h
+@@ -59,6 +59,14 @@ struct blk_keyslot_manager;
+ */
+ #define BLKCG_MAX_POLS 5
+
++static inline int blk_validate_block_size(unsigned int bsize)
++{
++ if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
++ return -EINVAL;
++
++ return 0;
++}
++
+ typedef void (rq_end_io_fn)(struct request *, blk_status_t);
+
+ /*
--- /dev/null
+From 1ae43851b18afe861120ebd7c426dc44f06bb2bd Mon Sep 17 00:00:00 2001
+From: Masami Hiramatsu <mhiramat@kernel.org>
+Date: Thu, 16 Sep 2021 15:23:12 +0900
+Subject: bootconfig: init: Fix memblock leak in xbc_make_cmdline()
+
+From: Masami Hiramatsu <mhiramat@kernel.org>
+
+commit 1ae43851b18afe861120ebd7c426dc44f06bb2bd upstream.
+
+Free unused memblock in a error case to fix memblock leak
+in xbc_make_cmdline().
+
+Link: https://lkml.kernel.org/r/163177339181.682366.8713781325929549256.stgit@devnote2
+
+Fixes: 51887d03aca1 ("bootconfig: init: Allow admin to use bootconfig for kernel command line")
+Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
+Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ init/main.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/init/main.c
++++ b/init/main.c
+@@ -380,6 +380,7 @@ static char * __init xbc_make_cmdline(co
+ ret = xbc_snprint_cmdline(new_cmdline, len + 1, root);
+ if (ret < 0 || ret > len) {
+ pr_err("Failed to print extra kernel cmdline.\n");
++ memblock_free(__pa(new_cmdline), len + 1);
+ return NULL;
+ }
+
--- /dev/null
+From a52f8a59aef46b59753e583bf4b28fccb069ce64 Mon Sep 17 00:00:00 2001
+From: Kees Cook <keescook@chromium.org>
+Date: Wed, 12 May 2021 21:51:10 -0700
+Subject: fortify: Explicitly disable Clang support
+
+From: Kees Cook <keescook@chromium.org>
+
+commit a52f8a59aef46b59753e583bf4b28fccb069ce64 upstream.
+
+Clang has never correctly compiled the FORTIFY_SOURCE defenses due to
+a couple bugs:
+
+ Eliding inlines with matching __builtin_* names
+ https://bugs.llvm.org/show_bug.cgi?id=50322
+
+ Incorrect __builtin_constant_p() of some globals
+ https://bugs.llvm.org/show_bug.cgi?id=41459
+
+In the process of making improvements to the FORTIFY_SOURCE defenses, the
+first (silent) bug (coincidentally) becomes worked around, but exposes
+the latter which breaks the build. As such, Clang must not be used with
+CONFIG_FORTIFY_SOURCE until at least latter bug is fixed (in Clang 13),
+and the fortify routines have been rearranged.
+
+Update the Kconfig to reflect the reality of the current situation.
+
+Signed-off-by: Kees Cook <keescook@chromium.org>
+Acked-by: Nick Desaulniers <ndesaulniers@google.com>
+Link: https://lore.kernel.org/lkml/CAKwvOd=A+ueGV2ihdy5GtgR2fQbcXjjAtVxv3=cPjffpebZB7A@mail.gmail.com
+Cc: Nathan Chancellor <nathan@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ security/Kconfig | 3 +++
+ 1 file changed, 3 insertions(+)
+
+--- a/security/Kconfig
++++ b/security/Kconfig
+@@ -191,6 +191,9 @@ config HARDENED_USERCOPY_PAGESPAN
+ config FORTIFY_SOURCE
+ bool "Harden common str/mem functions against buffer overflows"
+ depends on ARCH_HAS_FORTIFY_SOURCE
++ # https://bugs.llvm.org/show_bug.cgi?id=50322
++ # https://bugs.llvm.org/show_bug.cgi?id=41459
++ depends on !CC_IS_CLANG
+ help
+ Detect overflows of buffers in common string and memory functions
+ where the compiler can determine and validate the buffer sizes.
--- /dev/null
+From af3c570fb0df422b4906ebd11c1bf363d89961d5 Mon Sep 17 00:00:00 2001
+From: Xie Yongji <xieyongji@bytedance.com>
+Date: Tue, 26 Oct 2021 22:40:14 +0800
+Subject: loop: Use blk_validate_block_size() to validate block size
+
+From: Xie Yongji <xieyongji@bytedance.com>
+
+commit af3c570fb0df422b4906ebd11c1bf363d89961d5 upstream.
+
+Remove loop_validate_block_size() and use the block layer helper
+to validate block size.
+
+Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
+Link: https://lore.kernel.org/r/20211026144015.188-4-xieyongji@bytedance.com
+Signed-off-by: Jens Axboe <axboe@kernel.dk>
+Cc: Tadeusz Struk <tadeusz.struk@linaro.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/block/loop.c | 17 ++---------------
+ 1 file changed, 2 insertions(+), 15 deletions(-)
+
+--- a/drivers/block/loop.c
++++ b/drivers/block/loop.c
+@@ -229,19 +229,6 @@ static void __loop_update_dio(struct loo
+ }
+
+ /**
+- * loop_validate_block_size() - validates the passed in block size
+- * @bsize: size to validate
+- */
+-static int
+-loop_validate_block_size(unsigned short bsize)
+-{
+- if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
+- return -EINVAL;
+-
+- return 0;
+-}
+-
+-/**
+ * loop_set_size() - sets device size and notifies userspace
+ * @lo: struct loop_device to set the size for
+ * @size: new size of the loop device
+@@ -1121,7 +1108,7 @@ static int loop_configure(struct loop_de
+ }
+
+ if (config->block_size) {
+- error = loop_validate_block_size(config->block_size);
++ error = blk_validate_block_size(config->block_size);
+ if (error)
+ goto out_unlock;
+ }
+@@ -1617,7 +1604,7 @@ static int loop_set_block_size(struct lo
+ if (lo->lo_state != Lo_bound)
+ return -ENXIO;
+
+- err = loop_validate_block_size(arg);
++ err = blk_validate_block_size(arg);
+ if (err)
+ return err;
+
--- /dev/null
+fortify-explicitly-disable-clang-support.patch
+block-add-a-helper-to-validate-the-block-size.patch
+loop-use-blk_validate_block_size-to-validate-block-size.patch
+bootconfig-init-fix-memblock-leak-in-xbc_make_cmdline.patch