From patchwork Wed Jan 13 16:03:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12017233 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 7C389C433E0 for ; Wed, 13 Jan 2021 16:06:09 +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 231C223434 for ; Wed, 13 Jan 2021 16:06:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 231C223434 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=/1/MZP1lYvVcZ2b/IvLxZB9qp/g8XK632UaM1rgdIXo=; b=pTfmvCF6Y7xjly4XC9UZIZiZz 0WgN+KBm9nGwIxxbA9VefjgmS/wIg6GDTtHSrzqzW/Cr7MhZFGAOS/4/3hUzMZ9gtsNWdUH6ZjttW 0nFKg0V8yWQc+ThB0hdYgUYlJNv3EprSE1yT3u2zpGlRxtMDsA0fA0tNYPrF0nW4kx1iB5uLx8LIp rnsFeRhHr7zUhulMsNl8Qitneb6vbJP3ZUJzJmoa3qQcfAV5Ezf2tz64uMY/GEi3NN++9sVGBK+Tc K+RrliZaeg3l78P10X+PYyj2F125w0+Zo8Lb63XaLi9goa7B/1ep2PSiziGkRnHWVoyX1PoncY/JA cHGiplnTg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzici-0001NH-NZ; Wed, 13 Jan 2021 16:03:52 +0000 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzicc-0001IO-W4 for linux-arm-kernel@lists.infradead.org; Wed, 13 Jan 2021 16:03:48 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id x19so1766372qvv.16 for ; Wed, 13 Jan 2021 08:03:38 -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=S1gB0mX83HDDRDaVYmLzCgZEsoFxFZ697ly4fdy8+Ks=; b=onsW+t/YsYPW7Svrw7yWD2kvrRWEmrDqD+BcstXXpVYE27xuAbQnuH366baXFUJt7P q2byhvdnZS2pHRQEfzr8dVbYqGDMqWhQdCNgsLaH5LgIYs+rBzpKTp8X1s5UfXlW31fo e/LF6hRisIMf3tNYOwJcmN8ctzKnUVwtEIRdZdB2mCsOgt7eokJxnt8i1AF4kDp+r/Jn eMgyMsESgMNLluf6Q0Z8B4w9PFFgPGXC/zypWRSttrijEeUX1QAA6paSYDx1Ux9nv/MR oGsZEZ5ILg/XHhL4Wc9leIItNY5bZTBM2ML71iw/WcHGEoCcZ6vk7T14I7OM8Z3hQDyB fI0A== 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=S1gB0mX83HDDRDaVYmLzCgZEsoFxFZ697ly4fdy8+Ks=; b=Mj8xKiUef75ky3EtoiTKtn38NVf2HISAZ2wa8LFupoAdsCzZ8Oqu3v8/DrYIR/YREu 0QuMRzQ3VyIbBd+fygKbruLSpbEU74AJPZMExzjqvXty07EdUMFBv/7DyFFCkux0KJ7V 55jfW+wXO1I0TIYPFiuLxIMhCekh5RAu7u6qSrYHGyTYuL+MO17Qht/24adCdcUWkoP+ 2zITAWpr15Md2bnYaITPipagg/fMNuCkOjky2HRZfhrEI5Jsx2BGg7HLEVxuxUl84v0F 1dCOHTshythzRNWzR8pDsymdvvQjxu4O9J5Enktolw9k9NiZtMcUbMFJ9LhxFK9yUqG1 BAVA== X-Gm-Message-State: AOAM532lNt3sxoLXPBgBDE0L5+nIDy4i7DZQDmjkZi4nRom7vgYwl83o 8KzBrJNck5acSfl5lykoPKDmWakkUQmxxktJ X-Google-Smtp-Source: ABdhPJztlyDnxqW+tCluo1zQcHISh9MRheAbpgrcjhVfg6uiLIQBqjzru7wLvoT5T/oLsbWRseVQ28oyUeghjYDF X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a25:ac1f:: with SMTP id w31mr4193358ybi.87.1610553817007; Wed, 13 Jan 2021 08:03:37 -0800 (PST) Date: Wed, 13 Jan 2021 17:03:29 +0100 In-Reply-To: Message-Id: <7fbac00e4d155cf529517a165a48351dcf3c3156.1610553774.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH 1/2] kasan, mm: fix conflicts with init_on_alloc/free From: Andrey Konovalov To: 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-20210113_110347_043155_5CF39C11 X-CRM114-Status: GOOD ( 10.50 ) 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 , Andrew Morton , 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. Link: https://linux-review.googlesource.com/id/I50dd32838a666e173fe06c3c5c766f2c36aae901 Fixes: aa1ef4d7b3f67 ("kasan, mm: reset tags when accessing metadata") Reported-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov Acked-by: Vlastimil Babka --- 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 Wed Jan 13 16:03:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12017237 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 720A3C433E6 for ; Wed, 13 Jan 2021 16:06:11 +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 1F23523437 for ; Wed, 13 Jan 2021 16:06:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F23523437 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=Rnwnn8VrOWgZBFgnWQn9/2sgG Y/DsTtpa5kEm+clgm3s6ccH2Ao60rclcoiSDCbJ3Ch+iFgTL0tjKf96Zt/3wvgyScroya8CVjh8Rh oTT+p9Y3gewG4RA+PNzqfyg9nW/ToVlqQfwtLY+pkCB606M/xVCcfBgj89p6oF+IHCjrM/OYdJqtz J9QCMSAd9bIkRJpbXWdzmBusASDFHuU66AjLRHwe8btzZefQty/TOrwtggFnCy34e0vh9ZV4EsEbN LJWlVWpkx8pxMKcZXz+dJr5NgByf8MPZeaZxwHLYIz4M8HSNg6gRnKQuc2ENEqf4KYhC3FoE3o/1F gyMuhbPYw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzicm-0001P3-7J; Wed, 13 Jan 2021 16:03:56 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzicd-0001Jh-5A for linux-arm-kernel@lists.infradead.org; Wed, 13 Jan 2021 16:03:48 +0000 Received: by mail-wm1-x349.google.com with SMTP id o79so368839wme.9 for ; Wed, 13 Jan 2021 08:03:40 -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=CDyrzARrVWFbuNifeul+Ll6GNbUn3MtdKoa0QdzHXSOPzMxbXAa7Z/FvEsSB2IPRrW enMrgXSKOeK3msMJO/vfXcb+9JOTd7R8a1VjRZ/ULWPr0g5AiDXOpZfbVIA7QbmrjjLC fpV17EGOTCPZOpybyXa7JbPD6CKpgp0WKU6sVKxPLH+PNidH+RTGfKve7sdwxM0Z16FB LWD2vekX5jUN8zAAl7Sf8PityLr6lD8t0vPjkwswCG6Ru8XRUIb2jRtx4a3ElWN9jXGD 4CcvIiyT7b2Su7QJuJPuGTsoEbbxb2hkmLg2nDCnYXnMLK7KB4hqQnZEwCeqZha6aiPI OYfg== 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=sG82mcuXXCtsZZSHPaqgNztpJ7FnB5DUogQpwMgyV56DNM4R745lCsdOAXFprZpYRY gUrFqmsOxOF8sxgD2hq4+NR2qxyr7WbzQvKDLBXA+6XwVoobanSX/vDzTPcN1/psB3aB 5FAwVl2AscBEXmrdZOhez9xS7/ARcvCDDhWAmWGMbzZ5oMZKVuYONGw/9kAst7xapjvY xBVFCp+kAjERNQxoSU1t0IIjtsSHe7WqtN3vpw2IRArxb2Mz6z4M5yqF1wvQ2PO15ufp d7fHumVlw9M/qQo5OM5tDn8jBzzM6ChtyXHNBPBrGizxJ7LcKOEbN15jlL76YCq6ZPQq 1Aqg== X-Gm-Message-State: AOAM530/I7KSYHtKxn7H6O3ApVF0wbDwE+5B84wNBGWm3CA0jwyoQnW0 gmaaEhvEjwqlrJNLCjJAkSYe7C1VG6gSTKe2 X-Google-Smtp-Source: ABdhPJxqarOEyeKYbqGN5d2jvJR/uvZGjSvQgP26Nb2T8OhUp0hSrBOuQZdB1FVfKQ+fxQyDVc8hMJzo5rC3Fwoe X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6000:222:: with SMTP id l2mr3287308wrz.392.1610553819541; Wed, 13 Jan 2021 08:03:39 -0800 (PST) Date: Wed, 13 Jan 2021 17:03:30 +0100 In-Reply-To: Message-Id: <1965508bcbec62699715d32bef91628ef55b4b44.1610553774.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH 2/2] kasan, arm64: fix pointer tags in KASAN reports From: Andrey Konovalov To: 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-20210113_110347_214771_33653C97 X-CRM114-Status: GOOD ( 12.70 ) 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 , Andrew Morton , 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.