From patchwork Thu Jan 16 06:26:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 11336193 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 12A3E13B4 for ; Thu, 16 Jan 2020 06:26:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D27DF2075B for ; Thu, 16 Jan 2020 06:26:33 +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="oNmexNcV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D27DF2075B 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 029D48E0037; Thu, 16 Jan 2020 01:26:33 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EF5658E0026; Thu, 16 Jan 2020 01:26:32 -0500 (EST) 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 DBC908E0037; Thu, 16 Jan 2020 01:26:32 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0115.hostedemail.com [216.40.44.115]) by kanga.kvack.org (Postfix) with ESMTP id C24958E0026 for ; Thu, 16 Jan 2020 01:26:32 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 8B01B2C93 for ; Thu, 16 Jan 2020 06:26:32 +0000 (UTC) X-FDA: 76382513424.10.music78_905ce5479985c X-Spam-Summary: 2,0,0,45f59d70aaa328ea,d41d8cd98f00b204,dja@axtens.net,:linux-kernel@vger.kernel.org::kasan-dev@googlegroups.com:linuxppc-dev@lists.ozlabs.org:linux-arm-kernel@lists.infradead.org:linux-s390@vger.kernel.org:linux-xtensa@linux-xtensa.org:x86@kernel.org:dvyukov@google.com:christophe.leroy@c-s.fr: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: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.214.193:@axtens.net:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL :0,DNSBL X-HE-Tag: music78_905ce5479985c X-Filterd-Recvd-Size: 4355 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Thu, 16 Jan 2020 06:26:31 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id f20so7896131plj.5 for ; Wed, 15 Jan 2020 22:26:31 -0800 (PST) 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=jgsZ87j9zhFzITBOLkD7Zx7YPDB2pB7wEvRvkLTLK58=; b=oNmexNcVAh+3e35uSrHwMbT1gEdNtfFt+AsrrtqPXQmSRoQ2+dPRtMo5LTrIw10hkD u+AKJkLOQ7ejO/lyaa6mLr7Bws1hotDPmNsiYytrmcuCElg5p/2U1uo544G1s8tNj3oi 67cF7zBrygv/ffmERc13Rw9w/bQ1CKyQ31T20= 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=jgsZ87j9zhFzITBOLkD7Zx7YPDB2pB7wEvRvkLTLK58=; b=GCX5YKvHbWXkCSXa+dd/PnQxmzFMGwS8OEr4ACucQiTUxk8WfA6GzbQID3jL9NNKG8 3QSelphmQhBsYt4tEfavJmk85HeXjS7c3AuzB/0Sr3C3nMCPxPlWvp4k29Nd/xN0IFwd t8NzDr6JB0OF+FFNY+sKwCkucImFQD2zkGNnvBOaxvtqeYzCjvXYGHtaDLNrZzdwfMRH fWC8TY4UcFV0QA/kJhEVstfA5VkcJnU13CVUjfW6y81mipa07fv4N93dXDdy+TvuCas3 EXV8xwVPrKxEXf8EQHgYO5S9W1deZVObf6rB26qUnmhmuW86Kw7Pq5uOPeZeHP5TgZ1B 9itA== X-Gm-Message-State: APjAAAWCe+nBlDppaCVjdnEQWJhTtBXJoSm2cZjzK55k8sJBvdweD+N/ vghbd3WuKrUZE1sYZPZRESBDQA== X-Google-Smtp-Source: APXvYqxr6t7CheZI96TYjHdF4c+2lQSa9v9KFUkO88U4heoEGDZYaqbW2enLJb4tzmBEKZ7QkJrRRA== X-Received: by 2002:a17:902:9307:: with SMTP id bc7mr29877693plb.338.1579155990819; Wed, 15 Jan 2020 22:26:30 -0800 (PST) Received: from localhost (2001-44b8-1113-6700-097c-7eed-afd4-cd15.static.ipv6.internode.on.net. [2001:44b8:1113:6700:97c:7eed:afd4:cd15]) by smtp.gmail.com with ESMTPSA id c68sm24184007pfc.156.2020.01.15.22.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2020 22:26:30 -0800 (PST) From: Daniel Axtens To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com Cc: linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, linux-xtensa@linux-xtensa.org, x86@kernel.org, dvyukov@google.com, christophe.leroy@c-s.fr, Daniel Axtens Subject: [PATCH v2 0/3] Fix some incompatibilites between KASAN and FORTIFY_SOURCE Date: Thu, 16 Jan 2020 17:26:22 +1100 Message-Id: <20200116062625.32692-1-dja@axtens.net> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000096, 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. Finally, test_memcmp used a stack array without explicit initialisation, which can sometimes break too, so fix that up. 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(-)