Message ID | 20191122112621.204798-3-glider@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add KernelMemorySanitizer infrastructure | expand |
On Fri, 22 Nov 2019 at 12:26, <glider@google.com> wrote: > > Clang may replace stackdepot_memcmp() with a call to instrumented bcmp(), > which is exactly what we wanted to avoid creating stackdepot_memcmp(). > Building the file with -fno-builtin prevents such optimizations. > > Signed-off-by: Alexander Potapenko <glider@google.com> > To: Alexander Potapenko <glider@google.com> > Cc: Vegard Nossum <vegard.nossum@oracle.com> > Cc: Dmitry Vyukov <dvyukov@google.com> > Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> > Cc: Arnd Bergmann <arnd@arndb.de> > Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> > Cc: linux-mm@kvack.org > --- > This patch was previously called "stackdepot: prevent Clang from optimizing > away stackdepot_memcmp()". > > v3: > - use -fno-builtin instead of a barrier > > Change-Id: I4495b617b15c0ab003a61c1f0d54d0026fa8b144 > --- > lib/Makefile | 4 ++++ > lib/stackdepot.c | 2 +- > 2 files changed, 5 insertions(+), 1 deletion(-) > > diff --git a/lib/Makefile b/lib/Makefile > index c5892807e06f..58a3e1b1a868 100644 > --- a/lib/Makefile > +++ b/lib/Makefile > @@ -215,6 +215,10 @@ obj-$(CONFIG_SG_POOL) += sg_pool.o > obj-$(CONFIG_STMP_DEVICE) += stmp_device.o > obj-$(CONFIG_IRQ_POLL) += irq_poll.o > > +# stackdepot.c should not be instrumented or call instrumented functions. > +# Prevent the compiler from calling builtins like memcmp() or bcmp() from this > +# file. > +CFLAGS_stackdepot.o += -fno-builtin > obj-$(CONFIG_STACKDEPOT) += stackdepot.o > KASAN_SANITIZE_stackdepot.o := n > KCOV_INSTRUMENT_stackdepot.o := n > diff --git a/lib/stackdepot.c b/lib/stackdepot.c > index 0bc6182bc7a6..6d1123123e56 100644 > --- a/lib/stackdepot.c > +++ b/lib/stackdepot.c > @@ -163,7 +163,7 @@ int stackdepot_memcmp(const unsigned long *u1, const unsigned long *u2, > unsigned int n) > { > for ( ; n-- ; u1++, u2++) { > - if (*u1 != *u2) > + if ((*u1) != (*u2)) Why this change? Can stackdepot.c be reverted? > return 1; > } > return 0; > -- > 2.24.0.432.g9d3f5f5b63-goog >
diff --git a/lib/Makefile b/lib/Makefile index c5892807e06f..58a3e1b1a868 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -215,6 +215,10 @@ obj-$(CONFIG_SG_POOL) += sg_pool.o obj-$(CONFIG_STMP_DEVICE) += stmp_device.o obj-$(CONFIG_IRQ_POLL) += irq_poll.o +# stackdepot.c should not be instrumented or call instrumented functions. +# Prevent the compiler from calling builtins like memcmp() or bcmp() from this +# file. +CFLAGS_stackdepot.o += -fno-builtin obj-$(CONFIG_STACKDEPOT) += stackdepot.o KASAN_SANITIZE_stackdepot.o := n KCOV_INSTRUMENT_stackdepot.o := n diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 0bc6182bc7a6..6d1123123e56 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -163,7 +163,7 @@ int stackdepot_memcmp(const unsigned long *u1, const unsigned long *u2, unsigned int n) { for ( ; n-- ; u1++, u2++) { - if (*u1 != *u2) + if ((*u1) != (*u2)) return 1; } return 0;
Clang may replace stackdepot_memcmp() with a call to instrumented bcmp(), which is exactly what we wanted to avoid creating stackdepot_memcmp(). Building the file with -fno-builtin prevents such optimizations. Signed-off-by: Alexander Potapenko <glider@google.com> To: Alexander Potapenko <glider@google.com> Cc: Vegard Nossum <vegard.nossum@oracle.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: linux-mm@kvack.org --- This patch was previously called "stackdepot: prevent Clang from optimizing away stackdepot_memcmp()". v3: - use -fno-builtin instead of a barrier Change-Id: I4495b617b15c0ab003a61c1f0d54d0026fa8b144 --- lib/Makefile | 4 ++++ lib/stackdepot.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-)