From patchwork Thu Jan 14 19:33:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12020709 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 3B28FC433E6 for ; Thu, 14 Jan 2021 19:35:55 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DCEF323877 for ; Thu, 14 Jan 2021 19:35:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DCEF323877 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=MmU7AhIDjvh6HSUFt+mJAntEqUBhXY7HchVPGjQf7yg=; b=OhsX2WuwmP0BzcvSWmSKchdJN cGUhnh5Qh66iQHo0dmT41x8MguHbsuCVMl2hmKrx9HRoOxQGkdcd3Tj9ONBwoG9YPGc7nNfNA5Tk+ c4O1b2Cn4W50OdYPo7yXv7+ir7VFvqlQatKzMWsFHvCVonnW/OHeeIfvS4DsuDhmmUSis+vX4O/dd BBdPBykiQusU0FnBg/crNVUQ6w8stIjejQK6yhj31r6UrQegpLspuAPWHePhAbvOZooG1ECxrUwhZ JsEFhy1jjnVLs8C2aLyvj2mmdI8cyAnfz4Vjy0cFHXKtmOTZhTGuLwqHZoAriOBc02lpOftL/dOdM WiqyfpDLA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l08O2-0003PZ-8J; Thu, 14 Jan 2021 19:34:26 +0000 Received: from mail-ed1-x549.google.com ([2a00:1450:4864:20::549]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l08Nn-0003IW-Ig for linux-arm-kernel@lists.infradead.org; Thu, 14 Jan 2021 19:34:13 +0000 Received: by mail-ed1-x549.google.com with SMTP id cm4so2806511edb.0 for ; Thu, 14 Jan 2021 11:34:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=K3THHtce7/ygl6Gpfs3Di2sEUO2VBikWbOhVCkSY9ac=; b=vGVmZqHj/AbJ1AfEndnv5qhN+kxXpODExe7oS5E1yEmi9WEhI0SfOrlYPGX55Bl5S5 IAj/+Mw7dd5aBsSYNH5jX2rqXbsXhFP6e6PPixAuxk0wrqZ8unG4KH7Cw/eVhGJTGviN lPkgslaukDbGTN/Gv7djiu445f3483hEM3Ad6vdiOVFB6a05Sit/uI9otkaqdljywR+C v6tF/BLbualYuwQqKuaZJ6I8BIhCsGVVmIFVwUEHBeIG26BFXuW0fwgIBrX43LYTrGWH yeDapqJs1tPTHyAjsYyRfn5TLAJLj6+r7IU3blDikAT/jQG8jRfHtzStwmTf/yeR+4iE mdVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=K3THHtce7/ygl6Gpfs3Di2sEUO2VBikWbOhVCkSY9ac=; b=f+yKi0J9ffV8i8QvlGTJT2DaXozqkVD7z+s4s/qfmSoYPRyD7Ipv3C9O2JoWpb9xZu WaccYVAK30P6mC4Y+TwJKxTnQoCAK97t/xOCTf0RZPBJ0qHOzQlgex4SsYhpc8DB0+yB eV8/t/tYjrwVlNNGJ3eYJoS2ziGjPQNbUYL7X8KqNP1QnwjIDDSH40aUvyCgkEGJO0Np /WumabQAnZdP3tq9FyInJnJCY8ROtA4X0374eZJeRnIL+F1KLrccsXOuLL2sjNUizJui 7ttaMtszXRzLa5zEYMLfbs90+PW0W853EY0YGu/3l34RplIDVdp6b49pzUINoN2fCBLW vL2w== X-Gm-Message-State: AOAM533Et3gO+16PRtSzKlI0IO9crA13ENLdKAM9U8lzGLMrc+pQjhd3 0I9zBEr4QicaweIR55tKoyIgvUMVn6KKVb3F X-Google-Smtp-Source: ABdhPJyemLAvJCZ5NV1PNi6ia9mIG5BPvNuaojX/Vqve5Fg8GAq9MsC5vRUJBJF4bO4tLtErmJICS+Uki60iFkJH X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a17:906:578e:: with SMTP id k14mr6448146ejq.90.1610652846821; Thu, 14 Jan 2021 11:34:06 -0800 (PST) Date: Thu, 14 Jan 2021 20:33:56 +0100 In-Reply-To: Message-Id: <89cd4db80c3ee8c1975eb9171e99fcbc894eb1dd.1610652791.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH v2 1/2] kasan, mm: fix conflicts with init_on_alloc/free From: Andrey Konovalov To: Andrew Morton , Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Marco Elver X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210114_143411_771677_D3047CC1 X-CRM114-Status: GOOD ( 10.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Branislav Rankov , Vlastimil Babka , Andrey Konovalov , Kevin Brodsky , Will Deacon , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Andrey Ryabinin , Peter Collingbourne , Evgenii Stepanov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org A few places where SLUB accesses object's data or metadata were missed in a previous patch. This leads to false positives with hardware tag-based KASAN when bulk allocations are used with init_on_alloc/free. Fix the false-positives by resetting pointer tags during these accesses. (The kasan_reset_tag call is removed from slab_alloc_node, as it's added into maybe_wipe_obj_freeptr.) Link: https://linux-review.googlesource.com/id/I50dd32838a666e173fe06c3c5c766f2c36aae901 Fixes: aa1ef4d7b3f67 ("kasan, mm: reset tags when accessing metadata") Reported-by: Dmitry Vyukov Acked-by: Vlastimil Babka Signed-off-by: Andrey Konovalov --- mm/slub.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index dc5b42e700b8..75fb097d990d 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2791,7 +2791,8 @@ static __always_inline void maybe_wipe_obj_freeptr(struct kmem_cache *s, void *obj) { if (unlikely(slab_want_init_on_free(s)) && obj) - memset((void *)((char *)obj + s->offset), 0, sizeof(void *)); + memset((void *)((char *)kasan_reset_tag(obj) + s->offset), + 0, sizeof(void *)); } /* @@ -2883,7 +2884,7 @@ static __always_inline void *slab_alloc_node(struct kmem_cache *s, stat(s, ALLOC_FASTPATH); } - maybe_wipe_obj_freeptr(s, kasan_reset_tag(object)); + maybe_wipe_obj_freeptr(s, object); if (unlikely(slab_want_init_on_alloc(gfpflags, s)) && object) memset(kasan_reset_tag(object), 0, s->object_size); @@ -3329,7 +3330,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size, int j; for (j = 0; j < i; j++) - memset(p[j], 0, s->object_size); + memset(kasan_reset_tag(p[j]), 0, s->object_size); } /* memcg and kmem_cache debug support */ From patchwork Thu Jan 14 19:33:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12020707 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 0B5ABC433E0 for ; Thu, 14 Jan 2021 19:35:54 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B70F623877 for ; Thu, 14 Jan 2021 19:35:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B70F623877 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xlG0skpLhwPJsd2eXDfMWrqbt0VoIFkc972Qitq7q6w=; b=XeEPhwqoPkMkfuFynhHeFcy+l PP13MJgVQbxFP8hfCpuDxkUbUFWzzgZ6GGWLqq1K/I20nlmYAQ6r/mOizczU0CWvqI8h7fRdTSvqG fqR/UmcRIs5JbZiWKzg2EF/jsqHIObwa4/WKMf+br4BvZ9l4hFqEtcY01iTgOrmREuQnbudaai6Bj 6KGS+iNlQbFwCJ89JktsDPjVWqM+/b+ZxmTn5mw26DPiaHK2mF/Fwo25c9cZYkik2KsqWRK7AiMig y28nLFBxu8mIUNlHP9DmCBrhKwjXxNPkdsRdxkMxgLnKKDhSPcoKXcll/Kr/2NyY5HyOHfl72guA5 drkVMduzg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l08O6-0003QA-NP; Thu, 14 Jan 2021 19:34:30 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l08Np-0003Jm-6T for linux-arm-kernel@lists.infradead.org; Thu, 14 Jan 2021 19:34:15 +0000 Received: by mail-wm1-x34a.google.com with SMTP id x12so883262wmk.7 for ; Thu, 14 Jan 2021 11:34:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=TionkskhfJFUpeI/OKXUNvEID4OHoy9zg6Ffh7JmH8U=; b=Tmcmrez4gPLu4Ao5W6Ccspbbz/R7JDIQvAnzbn+3G4Nl+qd6kld//XQZFt8zyyKRHg yOZ6Hu2PtRCHValTBXFNafp8KmlGrnUDUAXIIy2UqKUlLWABYeG9e1tSa5OwJT7R1/P7 Rl6SImK21+uKZNX8VftBxTn6OW6YV9Aaog4tVh9+FKNf0qqtQzHnB2JVq8UfhfrB2ubN Q2jDUtL3U4qTeMG5T6Ebd7+wLZB4itXhgaGrwHMrFb5yfK+U6ZC9NWkwlcdo68gvP7YH W/Ko5xuUT7nB5U95hBn1BCKSkOqOiq7PFoxyUYHGWJ4/r702Cvk4YkGK2S/Rl6thA4Aj lk+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=TionkskhfJFUpeI/OKXUNvEID4OHoy9zg6Ffh7JmH8U=; b=c2rGBnT29Aus3C6lsTx0l9EDHEC8uzJh/XpBBkzSNdEdEkelno9r9dHo77Dsfo0WCo xjrd7nTtC7v87bpFSeFSkOltZiVhMYLrf6UiUcEICpKSNHDoKmTnwjAkR4NELm7EqMV8 UzMfvIW3PDM1C9lt0b/R/GMyjoa9XAGOp1/gccl+PI0aRlToPA5qKY4ROgjnB55S9iGD Eewi96aww0kVU7h+TrhIuwJYhE/EAeQQHV+stf5Vxjld5ou6LcQTto5LJenV0eagEzxq h8Rk5N2MmW32OpEOF2mQF8Ld6hDjfOU8iCZUZDqgbM8xjPi1szUoBswt5W7rJ7XUP7uQ TnzQ== X-Gm-Message-State: AOAM5303OYZs6jYvJGoHGkpSC1ZoNIRVKUbFCi0CML8DC8xB2NX+ZLy+ N6pMGoRy85MOkzDyHGvrUL+jd5+1YsYxvbPM X-Google-Smtp-Source: ABdhPJylLY1qXjASFBn9qVlbl1hTVHoUqtlGUBIy0x809OMseLmfOem7fnoyJjhZNOnosh+W97YAAaV/IKXRcqtt X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:600c:258:: with SMTP id 24mr5507364wmj.16.1610652849704; Thu, 14 Jan 2021 11:34:09 -0800 (PST) Date: Thu, 14 Jan 2021 20:33:57 +0100 In-Reply-To: Message-Id: <3d9e6dece676e9da49d9913c78fd647db7dad552.1610652791.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH v2 2/2] kasan, arm64: fix pointer tags in KASAN reports From: Andrey Konovalov To: Andrew Morton , Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Marco Elver X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210114_143413_300489_ABF41225 X-CRM114-Status: GOOD ( 12.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Branislav Rankov , Andrey Konovalov , Kevin Brodsky , Will Deacon , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Andrey Ryabinin , Peter Collingbourne , Evgenii Stepanov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org As of the "arm64: expose FAR_EL1 tag bits in siginfo" patch, the address that is passed to report_tag_fault has pointer tags in the format of 0x0X, while KASAN uses 0xFX format (note the difference in the top 4 bits). Fix up the pointer tag before calling kasan_report. Link: https://linux-review.googlesource.com/id/I9ced973866036d8679e8f4ae325de547eb969649 Fixes: dceec3ff7807 ("arm64: expose FAR_EL1 tag bits in siginfo") Fixes: 4291e9ee6189 ("kasan, arm64: print report from tag fault handler") Signed-off-by: Andrey Konovalov --- arch/arm64/mm/fault.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 3c40da479899..a218f6f2fdc8 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -304,6 +304,8 @@ static void report_tag_fault(unsigned long addr, unsigned int esr, { bool is_write = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) != 0; + /* The format of KASAN tags is 0xF. */ + addr |= (0xF0UL << MTE_TAG_SHIFT); /* * SAS bits aren't set for all faults reported in EL1, so we can't * find out access size.