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 21F27C33CB3 for ; Wed, 15 Jan 2020 06:37:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DC60D2467C for ; Wed, 15 Jan 2020 06:37: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="Osp9npf9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC60D2467C 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 6F4608E0005; Wed, 15 Jan 2020 01:37:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A2858E0003; Wed, 15 Jan 2020 01:37:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B9738E0005; Wed, 15 Jan 2020 01:37:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0035.hostedemail.com [216.40.44.35]) by kanga.kvack.org (Postfix) with ESMTP id 426D38E0003 for ; Wed, 15 Jan 2020 01:37:33 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 00B718248047 for ; Wed, 15 Jan 2020 06:37:32 +0000 (UTC) X-FDA: 76378912344.03.end47_24c0eee02da5e X-HE-Tag: end47_24c0eee02da5e X-Filterd-Recvd-Size: 4429 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Jan 2020 06:37:32 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id q8so8018296pfh.7 for ; Tue, 14 Jan 2020 22:37:32 -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=SZL5+wtQV8L4I+t/B21mqCEwpOPwMzNG/NjS3uxYK18=; b=Osp9npf9DMbWRL/vufgokGg2WptMrjKk3OPeCm/0ik25WiMSpPAb4kujwVnvH7fOil oU+ORo+jZAMiq5H28oyIZLUvOcanWtdUkJ1mlpumXIg2C+EfGVsiU2cpuQimXlNAFfD2 CVNZ4fDwlbPddmZWH/mpOH9zJsOU7fOaymLRM= 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=SZL5+wtQV8L4I+t/B21mqCEwpOPwMzNG/NjS3uxYK18=; b=cwiyC2rfxAX3E+VejMHeQfL2WktMGz3yaNO8/c/lR2oaYued8H2eZ1X+F4d4B8AIpS fcfKgcU0cBPKdLt3fFLCOHC6L8m/kXQZPiql4xBsu1eIHf8pHV2qWVemAGQZRIiNNu0O /v7NqHoY/YrxyVKEnESCjZXQEFTY472XumdCR/K5NQSEAygBizfYKgonAuTiIVYHhCfr dw4t0ntskfjxZt1uJt+Rju+AP+eT2HWx6C+RiJZPpu+Jf0xKUUvDQwjxqR9kc0yIe/Km gbuUeOsAC6vuNA9pthUzHscvkj2ry03Ho45NPGDmyU63N0BVT1WbUW1s3EzmKUQ2H7oQ aYCg== X-Gm-Message-State: APjAAAVnAqnFgZ2jQfVG8vfVo9Rdkt6WEA3+jbCKm2Dupqd6cKbCcG2Z 8D2BBONqnnQxgTfW33fgEtDzUA== X-Google-Smtp-Source: APXvYqz6twM/JSD4CFgc2SQAuWMMi7JwPofxcZnEA5RSwS0BHmT29NIEpqvWOQK7nIn36loT9ArrVg== X-Received: by 2002:a63:2949:: with SMTP id p70mr31822201pgp.191.1579070251356; Tue, 14 Jan 2020 22:37:31 -0800 (PST) Received: from localhost (2001-44b8-1113-6700-8d73-bc9d-5592-cfd7.static.ipv6.internode.on.net. [2001:44b8:1113:6700:8d73:bc9d:5592:cfd7]) by smtp.gmail.com with ESMTPSA id k12sm18720866pgm.65.2020.01.14.22.37.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 22:37: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, Daniel Axtens Subject: [PATCH 0/2] Fix some incompatibilites between KASAN and FORTIFY_SOURCE Date: Wed, 15 Jan 2020 17:37:08 +1100 Message-Id: <20200115063710.15796-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.000001, 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. As a result, we're also able to remove a snippet of code copy-pasted between every KASAN implementation that tries (largely unsuccessfully) to disable FORTIFY_SOURCE under KASAN. Daniel Axtens (2): kasan: stop tests being eliminated as dead code with FORTIFY_SOURCE string.h: fix incompatibility between FORTIFY_SOURCE and KASAN arch/arm64/include/asm/string.h | 4 --- arch/powerpc/include/asm/string.h | 4 --- arch/s390/include/asm/string.h | 4 --- arch/x86/include/asm/string_64.h | 4 --- arch/xtensa/include/asm/string.h | 3 -- include/linux/string.h | 49 +++++++++++++++++++++++-------- lib/test_kasan.c | 30 ++++++++++++------- 7 files changed, 56 insertions(+), 42 deletions(-) --=20 2.20.1