Patch "ubsan: implement __ubsan_handle_alignment_assumption" has been added to the 5.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    ubsan: implement __ubsan_handle_alignment_assumption

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     ubsan-implement-__ubsan_handle_alignment_assumption.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit d4a509845981d18a80ab924af4bc19e24bb331c9
Author: Nathan Chancellor <nathan@xxxxxxxxxx>
Date:   Thu Feb 4 18:32:57 2021 -0800

    ubsan: implement __ubsan_handle_alignment_assumption
    
    [ Upstream commit 28abcc963149e06d956d95a18a85f4ba26af746f ]
    
    When building ARCH=mips 32r2el_defconfig with CONFIG_UBSAN_ALIGNMENT:
    
      ld.lld: error: undefined symbol: __ubsan_handle_alignment_assumption
         referenced by slab.h:557 (include/linux/slab.h:557)
                       main.o:(do_initcalls) in archive init/built-in.a
         referenced by slab.h:448 (include/linux/slab.h:448)
                       do_mounts_rd.o:(rd_load_image) in archive init/built-in.a
         referenced by slab.h:448 (include/linux/slab.h:448)
                       do_mounts_rd.o:(identify_ramdisk_image) in archive init/built-in.a
         referenced 1579 more times
    
    Implement this for the kernel based on LLVM's
    handleAlignmentAssumptionImpl because the kernel is not linked against
    the compiler runtime.
    
    Link: https://github.com/ClangBuiltLinux/linux/issues/1245
    Link: https://github.com/llvm/llvm-project/blob/llvmorg-11.0.1/compiler-rt/lib/ubsan/ubsan_handlers.cpp#L151-L190
    Link: https://lkml.kernel.org/r/20210127224451.2587372-1-nathan@xxxxxxxxxx
    Signed-off-by: Nathan Chancellor <nathan@xxxxxxxxxx>
    Acked-by: Kees Cook <keescook@xxxxxxxxxxxx>
    Reviewed-by: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
    Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/lib/ubsan.c b/lib/ubsan.c
index cb9af3f6b77e3..adf8dcf3c84e6 100644
--- a/lib/ubsan.c
+++ b/lib/ubsan.c
@@ -427,3 +427,34 @@ void __ubsan_handle_load_invalid_value(void *_data, void *val)
 	ubsan_epilogue();
 }
 EXPORT_SYMBOL(__ubsan_handle_load_invalid_value);
+
+void __ubsan_handle_alignment_assumption(void *_data, unsigned long ptr,
+					 unsigned long align,
+					 unsigned long offset);
+void __ubsan_handle_alignment_assumption(void *_data, unsigned long ptr,
+					 unsigned long align,
+					 unsigned long offset)
+{
+	struct alignment_assumption_data *data = _data;
+	unsigned long real_ptr;
+
+	if (suppress_report(&data->location))
+		return;
+
+	ubsan_prologue(&data->location, "alignment-assumption");
+
+	if (offset)
+		pr_err("assumption of %lu byte alignment (with offset of %lu byte) for pointer of type %s failed",
+		       align, offset, data->type->type_name);
+	else
+		pr_err("assumption of %lu byte alignment for pointer of type %s failed",
+		       align, data->type->type_name);
+
+	real_ptr = ptr - offset;
+	pr_err("%saddress is %lu aligned, misalignment offset is %lu bytes",
+	       offset ? "offset " : "", BIT(real_ptr ? __ffs(real_ptr) : 0),
+	       real_ptr & (align - 1));
+
+	ubsan_epilogue();
+}
+EXPORT_SYMBOL(__ubsan_handle_alignment_assumption);
diff --git a/lib/ubsan.h b/lib/ubsan.h
index 7b56c09473a98..9a0b71c5ff9fb 100644
--- a/lib/ubsan.h
+++ b/lib/ubsan.h
@@ -78,6 +78,12 @@ struct invalid_value_data {
 	struct type_descriptor *type;
 };
 
+struct alignment_assumption_data {
+	struct source_location location;
+	struct source_location assumption_location;
+	struct type_descriptor *type;
+};
+
 #if defined(CONFIG_ARCH_SUPPORTS_INT128)
 typedef __int128 s_max;
 typedef unsigned __int128 u_max;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux