From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755914AbdJLL3w (ORCPT ); Thu, 12 Oct 2017 07:29:52 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:14313 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751759AbdJLL3v (ORCPT ); Thu, 12 Oct 2017 07:29:51 -0400 From: "Liuwenliang (Lamb)" To: Dmitry Vyukov , Andrew Morton CC: Russell King - ARM Linux , Andrey Ryabinin , "afzal.mohd.ma@gmail.com" , "f.fainelli@gmail.com" , Laura Abbott , "Kirill A. Shutemov" , Michal Hocko , "cdall@linaro.org" , "marc.zyngier@arm.com" , Catalin Marinas , "Matthew Wilcox" , Thomas Gleixner , "Thomas Garnier" , Kees Cook , "Arnd Bergmann" , Vladimir Murzin , "tixy@linaro.org" , Ard Biesheuvel , "robin.murphy@arm.com" , Ingo Molnar , "grygorii.strashko@linaro.org" , Alexander Potapenko , "opendmb@gmail.com" , "linux-arm-kernel@lists.infradead.org" , LKML , kasan-dev , "linux-mm@kvack.org" , Jiazhenghua , Dailei , Zengweilin , Heshaoliang , "Liuwenliang (Lamb)" Subject: Re: [PATCH 06/11] change memory_is_poisoned_16 for aligned error Thread-Topic: [PATCH 06/11] change memory_is_poisoned_16 for aligned error Thread-Index: AQHTQmojkaS4eMNqlEmU+SfLBvVjH6LexQaAgACEIYCAAJFkoA== Date: Thu, 12 Oct 2017 11:27:40 +0000 Message-ID: References: <20171011082227.20546-1-liuwenliang@huawei.com> <20171011082227.20546-7-liuwenliang@huawei.com> <20171011162345.f601c29d12c81af85bf38565@linux-foundation.org> In-Reply-To: Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.57.90.243] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090203.59DF51BA.0019,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=169.254.11.236, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 5c6defd065ac67db1f83fcaeeb901107 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by nfs id v9CBUc9a032483 >> - I don't understand why this is necessary. memory_is_poisoned_16() >> already handles unaligned addresses? >> >> - If it's needed on ARM then presumably it will be needed on other >> architectures, so CONFIG_ARM is insufficiently general. >> >> - If the present memory_is_poisoned_16() indeed doesn't work on ARM, >> it would be better to generalize/fix it in some fashion rather than >> creating a new variant of the function. >Yes, I think it will be better to fix the current function rather then >have 2 slightly different copies with ifdef's. >Will something along these lines work for arm? 16-byte accesses are >not too common, so it should not be a performance problem. And >probably modern compilers can turn 2 1-byte checks into a 2-byte check >where safe (x86). >static __always_inline bool memory_is_poisoned_16(unsigned long addr) >{ > u8 *shadow_addr = (u8 *)kasan_mem_to_shadow((void *)addr); > > if (shadow_addr[0] || shadow_addr[1]) > return true; > /* Unaligned 16-bytes access maps into 3 shadow bytes. */ > if (unlikely(!IS_ALIGNED(addr, KASAN_SHADOW_SCALE_SIZE))) > return memory_is_poisoned_1(addr + 15); > return false; >} Thanks for Andrew Morton and Dmitry Vyukov's review. If the parameter addr=0xc0000008, now in function: static __always_inline bool memory_is_poisoned_16(unsigned long addr) { --- //shadow_addr = (u16 *)(KASAN_OFFSET+0x18000001(=0xc0000008>>3)) is not --- // unsigned by 2 bytes. u16 *shadow_addr = (u16 *)kasan_mem_to_shadow((void *)addr); /* Unaligned 16-bytes access maps into 3 shadow bytes. */ if (unlikely(!IS_ALIGNED(addr, KASAN_SHADOW_SCALE_SIZE))) return *shadow_addr || memory_is_poisoned_1(addr + 15); ---- //here is going to be error on arm, specially when kernel has not finished yet. ---- //Because the unsigned accessing cause DataAbort Exception which is not ---- //initialized when kernel is starting. return *shadow_addr; } I also think it is better to fix this problem.