From patchwork Fri Apr 24 14:55:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 11508043 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6624F92C for ; Fri, 24 Apr 2020 14:55:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 32AB720767 for ; Fri, 24 Apr 2020 14:55:29 +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="o941UkGJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32AB720767 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 61EF08E0005; Fri, 24 Apr 2020 10:55:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5D0A58E0003; Fri, 24 Apr 2020 10:55:28 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E62F8E0005; Fri, 24 Apr 2020 10:55:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id 358A98E0003 for ; Fri, 24 Apr 2020 10:55:28 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id EC8DE181AC9B6 for ; Fri, 24 Apr 2020 14:55:27 +0000 (UTC) X-FDA: 76743047094.07.spark62_12911bd5f185a X-Spam-Summary: 2,0,0,acab6f100872200c,d41d8cd98f00b204,dja@axtens.net,,RULES_HIT:41:152:355:379:541:973:988:989:1260:1277:1311:1313:1314:1345:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3874:4250:4605:5007:6261:6653:6691:7808:7875:8660:10004:10400:11639:11658:11914:12043:12048:12291:12294:12296:12297:12517:12519:12679:12683:12895:13069:13148:13161:13229:13230:13311:13357:13894:14096:14097:14394:14659:14721:21080:21444:21451:21627:30003:30012:30034:30054:30070:30090,0,RBL:209.85.210.196:@axtens.net:.lbl8.mailshell.net-66.100.201.201 62.2.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:71,LUA_SUMMARY:none X-HE-Tag: spark62_12911bd5f185a X-Filterd-Recvd-Size: 4213 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Apr 2020 14:55:27 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id z1so3223892pfn.3 for ; Fri, 24 Apr 2020 07:55:27 -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=SjOuEDkqyCRoQlGb4r++HBQnM1FePx7k1uf7opXgrlY=; b=o941UkGJMnQqHReNMbWxL/s8PxT7Ra9iuzc/rTi6AtklATqfagsoaIerZb4wffLG5F lzSYOwYjYqPg3Xr5oTHI3OmLPnG6PAnnyTlhS+ek2U1Qsq/ysubk0lB2C76z+e8TYhQY jay5eaXVB37EXo7ewPRPv1NSQ0Narw4Ofb/gw= 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=SjOuEDkqyCRoQlGb4r++HBQnM1FePx7k1uf7opXgrlY=; b=RtYltyDcU94D2hoRD1u/Ta1OkNf/iDvqc/A1Y70Vn5ukYA7XLcjduiHPwyHI07b+R8 8eTmsv8xZ3/m/zhHz0tfmVTQOjC5pKJOzr/gQXIeB2tTqW3CXlF5p2kvH1IzJrsGhkWr jWW07seyO7z8XODwXfGwO4cqL1Rg38leDpWxxrCtyN/QtAQH619xkfHPLhNfu7hGU8R4 SjZ2dl8lgNuk5VtSyORXImb4aqB5c30xNiAmiBtoyQBxWqQTAHnuM+Xv7yvwjZatbFVW Ru9Gd71QpzZoXfBd9y3dAQVO+A6jR+bFY9CgvRcv444UNu+9eL84+u+NUDv8zutwzNHl N2Lg== X-Gm-Message-State: AGi0PuYK8v68Sy82Bxu2jjxC6hvfudG3m4o2Ttb5eRpbWCC6UHxwEAQB SgwS492SgPb0vglCiqYru2k9Ww== X-Google-Smtp-Source: APiQypJAVNWj9fQBBoGPE6iHQ7TBvOGfksNnnLg93WhVg5iX6nGDZGRRCvk/6/c/yw/BgNehCNS2pw== X-Received: by 2002:aa7:92cc:: with SMTP id k12mr7642619pfa.184.1587740126558; Fri, 24 Apr 2020 07:55:26 -0700 (PDT) Received: from localhost (2001-44b8-1113-6700-fd06-aa7b-7508-4b8b.static.ipv6.internode.on.net. [2001:44b8:1113:6700:fd06:aa7b:7508:4b8b]) by smtp.gmail.com with ESMTPSA id 1sm5978738pff.151.2020.04.24.07.55.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 07:55:25 -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 v4 0/2] Fix some incompatibilites between KASAN and FORTIFY_SOURCE Date: Sat, 25 Apr 2020 00:55:19 +1000 Message-Id: <20200424145521.8203-1-dja@axtens.net> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 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 than emit a function call that goes out to a KASAN-instrumented implementation. The patches address each reason in turn. v4: Drop patch 3, it turns out I created that issue in patch 1! Include David's Tested-by. 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 (2): kasan: stop tests being eliminated as dead code with FORTIFY_SOURCE string.h: fix incompatibility between FORTIFY_SOURCE and KASAN include/linux/string.h | 60 +++++++++++++++++++++++++++++++++--------- lib/test_kasan.c | 29 +++++++++++++------- 2 files changed, 67 insertions(+), 22 deletions(-)