Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3495196imm; Wed, 5 Sep 2018 00:46:51 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZxSfzQI5FS2wiv68a30b9WijAY1/6nhm4mOxL2O6k+ONJqiAUr90XBLy7qMF3bRvbJkFJU X-Received: by 2002:a62:34c4:: with SMTP id b187-v6mr38539752pfa.15.1536133611459; Wed, 05 Sep 2018 00:46:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536133611; cv=none; d=google.com; s=arc-20160816; b=I3gCfIOTfxAKVWwiQytU6Shp6Fyj9fa5sjYydBCKwL9hBpyInpCl8GAbW3dPspT5ye QiuRaZPba5ERpn9MTPbKVe3EKrgIZVemmeIn2SJxg6NBECKuo+LlqC/nVx2jA9mJyzk5 BfQhicBjbcDGu6VU1GrQOP9PeLu+8DXbNrEXTqUqeTz1XCBmiGOLr+rJKm7OEWYTl1lq tT25jpgRU4rs0GobFL2mYviXh2PGcHdpvmjroSg4+nvDktlpoEx3sG9bqkY2qL1LEgpg Sqo/PNDs1KFMIx3MjIVsIbGIZSWYagBBVIcCKkADn8vlLpqLVA43YDRyGFMWNfWmXqzh NGtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=MAlf/i2ytQLs0C71+kU8BN/uUVx5P31/nfxR06hSFE0=; b=FPbe3qdnpDToq+uWGQ3LDLkV9aSSeIeU/UT/1TEL8dVhzdtV04h+puLIqcdhCHky5k eF5UazE5pVM6jHCeCW5eEsXJBXdM4lyUIwBbzqnUhmYdxP1H9AHegOSlNzCZCqyY2/gH zQv1jVjVbu5N4sLP5pWYEWfvtiS1zbxmgpGvqNTOQJRMtUgNMIH3inVrVdFtOzzDN8fl TSsvz3JIQNSsg8oyvuBHeMaR1epoTx2CXtYinTpGIIIlAPYPv/0cge6rb++MWxFnctcm 2oulPgny8zZbZQggD4rDn0FXPfaZobOINv+u86r37OxDcOExNW2GwN3NU+6qCv3mCauW pasQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j21-v6si1236466pgl.8.2018.09.05.00.46.36; Wed, 05 Sep 2018 00:46:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727745AbeIEMN5 (ORCPT + 99 others); Wed, 5 Sep 2018 08:13:57 -0400 Received: from lgeamrelo11.lge.com ([156.147.23.51]:60260 "EHLO lgeamrelo11.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbeIEMN4 (ORCPT ); Wed, 5 Sep 2018 08:13:56 -0400 Received: from unknown (HELO lgeamrelo01.lge.com) (156.147.1.125) by 156.147.23.51 with ESMTP; 5 Sep 2018 16:44:58 +0900 X-Original-SENDERIP: 156.147.1.125 X-Original-MAILFROM: kyeongdon.kim@lge.com Received: from unknown (HELO ?10.159.80.93?) (10.159.80.93) by 156.147.1.125 with ESMTP; 5 Sep 2018 16:44:56 +0900 X-Original-SENDERIP: 10.159.80.93 X-Original-MAILFROM: kyeongdon.kim@lge.com Subject: Re: Re: [PATCH v2] arm64: kasan: add interceptors for strcmp/strncmp functions To: Andrey Ryabinin Cc: catalin.marinas@arm.com, will.deacon@arm.com, glider@google.com, dvyukov@google.com, Jason@zx2c4.com, robh@kernel.org, ard.biesheuvel@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org References: <1535014606-176525-1-git-send-email-kyeongdon.kim@lge.com> <12d4e435-e229-b4af-4286-a53fa77cb09d@virtuozzo.com> From: Kyeongdon Kim Message-ID: <0bde837e-2804-c6d6-4bda-8b166bdcfc6b@lge.com> Date: Wed, 5 Sep 2018 16:44:54 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <12d4e435-e229-b4af-4286-a53fa77cb09d@virtuozzo.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-09-05 오전 1:24, Andrey Ryabinin wrote: > > > On 09/04/2018 01:10 PM, Andrey Ryabinin wrote: > > > > > > On 09/04/2018 09:59 AM, Kyeongdon Kim wrote: > > > >>>> +#undef strncmp > >>>> +int strncmp(const char *cs, const char *ct, size_t len) > >>>> +{ > >>>> + check_memory_region((unsigned long)cs, len, false, _RET_IP_); > >>>> + check_memory_region((unsigned long)ct, len, false, _RET_IP_); > >>> > >>> This will cause false positives. Both 'cs', and 'ct' could be less > than len bytes. > >>> > >>> There is no need in these interceptors, just use the C > implementations from lib/string.c > >>> like you did in your first patch. > >>> The only thing that was wrong in the first patch is that assembly > implementations > >>> were compiled out instead of being declared week. > >>> > >> Well, at first I thought so.. > >> I would remove diff code in /mm/kasan/kasan.c then use C > implementations in lib/string.c > >> w/ assem implementations as weak : > >> > >> diff --git a/lib/string.c b/lib/string.c > >> index 2c0900a..a18b18f 100644 > >> --- a/lib/string.c > >> +++ b/lib/string.c > >> @@ -312,7 +312,7 @@ size_t strlcat(char *dest, const char *src, > size_t count) > >>  EXPORT_SYMBOL(strlcat); > >>  #endif > >> > >> -#ifndef __HAVE_ARCH_STRCMP > >> +#if (defined(CONFIG_ARM64) && defined(CONFIG_KASAN)) || > !defined(__HAVE_ARCH_STRCMP) > > > > No. What part of "like you did in your first patch" is unclear to you? > > Just to be absolutely clear, I meant #ifdef out __HAVE_ARCH_* defines > like it has been done in this patch > http://lkml.kernel.org/r/<1534233322-106271-1-git-send-email-kyeongdon.kim@lge.com> > I understood what you're saying, but I might think the wrong patch. So, thinking about the other way as below: can pick up assem variant or c one, declare them as weak. --- diff --git a/arch/arm64/include/asm/string.h b/arch/arm64/include/asm/string.h index dd95d33..53a2ae0 100644 --- a/arch/arm64/include/asm/string.h +++ b/arch/arm64/include/asm/string.h @@ -22,11 +22,22 @@ extern char *strrchr(const char *, int c);  #define __HAVE_ARCH_STRCHR  extern char *strchr(const char *, int c); +#ifdef CONFIG_KASAN +extern int __strcmp(const char *, const char *); +extern int __strncmp(const char *, const char *, __kernel_size_t); + +#ifndef __SANITIZE_ADDRESS__ +#define strcmp(cs, ct) __strcmp(cs, ct) +#define strncmp(cs, ct, n) __strncmp(cs, ct, n) +#endif + +#else  #define __HAVE_ARCH_STRCMP  extern int strcmp(const char *, const char *);  #define __HAVE_ARCH_STRNCMP  extern int strncmp(const char *, const char *, __kernel_size_t); +#endif  #define __HAVE_ARCH_STRLEN  extern __kernel_size_t strlen(const char *); diff --git a/arch/arm64/kernel/arm64ksyms.c b/arch/arm64/kernel/arm64ksyms.c index d894a20..9aeffd5 100644 --- a/arch/arm64/kernel/arm64ksyms.c +++ b/arch/arm64/kernel/arm64ksyms.c @@ -50,6 +50,10 @@ EXPORT_SYMBOL(strcmp);  EXPORT_SYMBOL(strncmp);  EXPORT_SYMBOL(strlen);  EXPORT_SYMBOL(strnlen); +#ifdef CONFIG_KASAN +EXPORT_SYMBOL(__strcmp); +EXPORT_SYMBOL(__strncmp); +#endif  EXPORT_SYMBOL(memset);  EXPORT_SYMBOL(memcpy);  EXPORT_SYMBOL(memmove); diff --git a/arch/arm64/kernel/image.h b/arch/arm64/kernel/image.h index a820ed0..5ef7a57 100644 --- a/arch/arm64/kernel/image.h +++ b/arch/arm64/kernel/image.h @@ -110,6 +110,8 @@ __efistub___flush_dcache_area    = KALLSYMS_HIDE(__pi___flush_dcache_area);  __efistub___memcpy        = KALLSYMS_HIDE(__pi_memcpy);  __efistub___memmove        = KALLSYMS_HIDE(__pi_memmove);  __efistub___memset        = KALLSYMS_HIDE(__pi_memset); +__efistub___strcmp        = KALLSYMS_HIDE(__pi_strcmp); +__efistub___strncmp        = KALLSYMS_HIDE(__pi_strncmp);  #endif  __efistub__text            = KALLSYMS_HIDE(_text); diff --git a/arch/arm64/lib/strcmp.S b/arch/arm64/lib/strcmp.S index 471fe61..0dffef7 100644 --- a/arch/arm64/lib/strcmp.S +++ b/arch/arm64/lib/strcmp.S @@ -60,6 +60,8 @@ tmp3        .req    x9  zeroones    .req    x10  pos        .req    x11 +.weak strcmp +ENTRY(__strcmp)  ENTRY(strcmp)      eor    tmp1, src1, src2      mov    zeroones, #REP8_01 @@ -232,3 +234,4 @@ CPU_BE(    orr    syndrome, diff, has_nul )      sub    result, data1, data2, lsr #56      ret  ENDPIPROC(strcmp) +ENDPROC(__strcmp) diff --git a/arch/arm64/lib/strncmp.S b/arch/arm64/lib/strncmp.S index e267044..b2648c7 100644 --- a/arch/arm64/lib/strncmp.S +++ b/arch/arm64/lib/strncmp.S @@ -64,6 +64,8 @@ limit_wd    .req    x13  mask        .req    x14  endloop        .req    x15 +.weak strncmp +ENTRY(__strncmp)  ENTRY(strncmp)      cbz    limit, .Lret0      eor    tmp1, src1, src2 @@ -308,3 +310,4 @@ CPU_BE( orr    syndrome, diff, has_nul )      mov    result, #0      ret  ENDPIPROC(strncmp) +ENDPROC(__strncmp) -- Could you review this diff?