From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE4FAC54FCB for ; Thu, 23 Apr 2020 15:45:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A924320767 for ; Thu, 23 Apr 2020 15:45:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=axtens.net header.i=@axtens.net header.b="OVK4+lyU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A924320767 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 37A6F8E0005; Thu, 23 Apr 2020 11:45:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32ABF8E0003; Thu, 23 Apr 2020 11:45:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 219EB8E0005; Thu, 23 Apr 2020 11:45:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0194.hostedemail.com [216.40.44.194]) by kanga.kvack.org (Postfix) with ESMTP id 0017A8E0003 for ; Thu, 23 Apr 2020 11:45:10 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B1002180AD815 for ; Thu, 23 Apr 2020 15:45:10 +0000 (UTC) X-FDA: 76739543580.21.wave72_675e0eb2d7853 X-HE-Tag: wave72_675e0eb2d7853 X-Filterd-Recvd-Size: 4287 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Apr 2020 15:45:10 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id x15so3152815pfa.1 for ; Thu, 23 Apr 2020 08:45:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sHxljxjTpk2oBVN9jqQPNFsunhe5JYr63Xg+w6BjEk0=; b=OVK4+lyUyi3K2XxNxns66uFwMhNrBdcne/S7/UEjlw0E22jAQTHxvEqLBeqPOAPxFK X+jjDj0hqNMQkWzrHiZfGWnwvGlMB24GNj07YjCI2D3rKZ+5K+DDH+ZhzWUfOxvMYHc+ bbZBn3S1ZiSTV5hTJmxP8lKXGmBJdbONugF2Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sHxljxjTpk2oBVN9jqQPNFsunhe5JYr63Xg+w6BjEk0=; b=DlRqPDGPS9CLdZL3E4GbrfSsuoa6tI7GT9xrLVxXBWezqCMRlxGZjw61VZuM3qMVT4 AexFRyCVUvGh3wc4p8xs7gd6clnq/VEq5TPbb5u2YvN/W2mu03F9Kv9L2K/lDS4MnGTH o4ZieWag54ymvatPMaCq5NwJVC6BtQsLec9HJoid+Lek7PpHBDwT48ZorTBPtUBOAhsI SfdZTOrHut2bXNGA75mUmISyu/7vHn/IKVaI9pMFl8+vSHkwVZS4GMkCHrDUKhai5hT/ SZnKIHOKTQSoUYaVv/8arMLpKueBgW7lf4M5clk30IwIDQ/ByPpZHSjx2QHwhySnTPt0 MSFw== X-Gm-Message-State: AGi0PuYysUlqXxBVfru8nJ+L//ubb7f7hGnftT0HCSR589if7KSunlnI oEnAnCtfUeWKpXjaYvLUgC3FBA== X-Google-Smtp-Source: APiQypL2rXvy7qGsCVugJpqQ0AJTu54mjBe+WV8wdzmBABoHEz5ipyihDvyYwh/78HYmZ4bBDKu+Ww== X-Received: by 2002:a63:7805:: with SMTP id t5mr4611238pgc.141.1587656709247; Thu, 23 Apr 2020 08:45:09 -0700 (PDT) Received: from localhost (2001-44b8-111e-5c00-7979-720a-9390-aec6.static.ipv6.internode.on.net. [2001:44b8:111e:5c00:7979:720a:9390:aec6]) by smtp.gmail.com with ESMTPSA id u15sm2645383pjm.47.2020.04.23.08.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 08:45:08 -0700 (PDT) From: Daniel Axtens To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, kasan-dev@googlegroups.com Cc: dvyukov@google.com, christophe.leroy@c-s.fr, Daniel Axtens Subject: [PATCH v3 0/3] Fix some incompatibilites between KASAN and FORTIFY_SOURCE Date: Fri, 24 Apr 2020 01:45:00 +1000 Message-Id: <20200423154503.5103-1-dja@axtens.net> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 3 KASAN self-tests fail on a kernel with both KASAN and FORTIFY_SOURCE: memchr, memcmp and strlen. I have observed this on x86 and powerpc. When FORTIFY_SOURCE is on, a number of functions are replaced with fortified versions, which attempt to check the sizes of the operands. However, these functions often directly invoke __builtin_foo() once they have performed the fortify check. This breaks things in 2 ways: - the three function calls are technically dead code, and can be eliminated. When __builtin_ versions are used, the compiler can detect this. - Using __builtins may bypass KASAN checks if the compiler decides to inline it's own implementation as sequence of instructions, rather tha= n emit a function call that goes out to a KASAN-instrumented implementation. The patches address each reason in turn. Finally, test_memcmp used a stack array without explicit initialisation, which can sometimes break too, so fix that up. v3: resend with Reviewed-bys, hopefully for inclusion in 5.8. v2: - some cleanups, don't mess with arch code as I missed some wrinkles. - add stack array init (patch 3) Daniel Axtens (3): kasan: stop tests being eliminated as dead code with FORTIFY_SOURCE string.h: fix incompatibility between FORTIFY_SOURCE and KASAN kasan: initialise array in kasan_memcmp test include/linux/string.h | 60 +++++++++++++++++++++++++++++++++--------- lib/test_kasan.c | 32 +++++++++++++--------- 2 files changed, 68 insertions(+), 24 deletions(-) --=20 2.20.1