Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752257AbdLGBNB (ORCPT ); Wed, 6 Dec 2017 20:13:01 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:47893 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751718AbdLGBNA (ORCPT ); Wed, 6 Dec 2017 20:13:00 -0500 Subject: Re: [PATCH v2] ubsan: don't handle misaligned address when support unaligned access To: Andrew Morton References: <5b905d56-609e-3822-096a-3b93b3eb7675@huawei.com> <20171206164916.687d5006b7a49ef1149e7154@linux-foundation.org> CC: "linux-kernel@vger.kernel.org" , LinuxArm , David Laight , "Andrey Ryabinin" From: Ding Tianhong Message-ID: Date: Thu, 7 Dec 2017 09:11:07 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20171206164916.687d5006b7a49ef1149e7154@linux-foundation.org> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.23.32] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3269 Lines: 93 Hi Andrew: Sorry for the mistaken of the Andrey's email. After the test I found this version still exist the problem that will transfer the align problem to size mismatch, I will send a new version to fix it. The correct way is like this: diff --git a/lib/ubsan.c b/lib/ubsan.c index fb0409d..0799678 100644 --- a/lib/ubsan.c +++ b/lib/ubsan.c @@ -321,9 +321,10 @@ void __ubsan_handle_type_mismatch(struct type_mismatch_data *data, if (!ptr) handle_null_ptr_deref(data); - else if (data->alignment && !IS_ALIGNED(ptr, data->alignment)) - handle_missaligned_access(data, ptr); - else + else if (data->alignment && !IS_ALIGNED(ptr, data->alignment)) { + if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) + handle_missaligned_access(data, ptr); + } else handle_object_size_mismatch(data, ptr); } EXPORT_SYMBOL(__ubsan_handle_type_mismatch); -- Thanks Ding On 2017/12/7 8:49, Andrew Morton wrote: > (correcting Andrey's email address) > > > From: Ding Tianhong > Subject: lib/ubsan.c: don't handle misaligned address when kernel supports unaligned access > > ubsan reports a warning like: > > UBSAN: Undefined behaviour in ../include/linux/etherdevice.h:386:9 > load of misaligned address ffffffc069ba0482 for type 'long unsigned int' > which requires 8 byte alignment > CPU: 0 PID: 901 Comm: sshd Not tainted 4.xx+ #1 > Hardware name: linux,dummy-virt (DT) > Call trace: > [] dump_backtrace+0x0/0x348 > [] show_stack+0x20/0x30 > [] dump_stack+0x144/0x1b4 > [] ubsan_epilogue+0x18/0x74 > [] __ubsan_handle_type_mismatch+0x1a0/0x25c > [] dev_gro_receive+0x17d8/0x1830 > [] napi_gro_receive+0x30/0x158 > [] virtnet_receive+0xad4/0x1fa8 > > The reason is that when enabling the CONFIG_UBSAN_ALIGNMENT, ubsan will > report the unaligned access even if the system supports it > (CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y). This produces a lot of noise > in the log and causes confusion. > > Prevent the detection of unaligned access when the system support > unaligned access. > > Link: http://lkml.kernel.org/r/5b905d56-609e-3822-096a-3b93b3eb7675@huawei.com > Signed-off-by: Ding Tianhong > Cc: David Laight > Cc: Andrey Ryabinin > Signed-off-by: Andrew Morton > --- > > lib/ubsan.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff -puN lib/ubsan.c~ubsan-dont-handle-misaligned-address-when-support-unaligned-access lib/ubsan.c > --- a/lib/ubsan.c~ubsan-dont-handle-misaligned-address-when-support-unaligned-access > +++ a/lib/ubsan.c > @@ -322,7 +322,8 @@ void __ubsan_handle_type_mismatch(struct > if (!ptr) > handle_null_ptr_deref(data); > else if (data->alignment && !IS_ALIGNED(ptr, data->alignment)) > - handle_missaligned_access(data, ptr); > + if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) > + handle_missaligned_access(data, ptr); > else > handle_object_size_mismatch(data, ptr); > } > _ > > > . >