From patchwork Fri Jan 15 17:41:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12023471 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 77FB5C433DB for ; Fri, 15 Jan 2021 17:43:25 +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 37A3A23A59 for ; Fri, 15 Jan 2021 17:43:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37A3A23A59 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=u++soPRZauuLXc/gVJW/Glj3r MNVSfMl+wPRhX3iT+B30rDjDhV2xKKZbu09yysIZyFffP4MnvdEwvGHaHysg1ZEOW5qFhEy7tJJwi wAPvHD4rlewIBX8M4CvtB6dCXJRWzP9lkELK4BcUt95s+swuHjERcb/NQawxVZq49CAArOKUNnNsQ LFwwO1BYRVlB8HXyJesD/ToWUD2lMmcaAofChUiifAboQQN3SbreW5T08KiM2Tt7p1ckMNK2QHBO+ mV9MfE1ryR106EPL51OHVVMG4uH2IsFVfOFvDlNYtSNjzzZFfNy2baqKluxsaVXwfWwTt/3VkpwEE CwMalv1rA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0T6v-00023m-4e; Fri, 15 Jan 2021 17:42:09 +0000 Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0T6q-00021Z-0L for linux-arm-kernel@lists.infradead.org; Fri, 15 Jan 2021 17:42:05 +0000 Received: by mail-qv1-xf49.google.com with SMTP id t18so8344146qva.6 for ; Fri, 15 Jan 2021 09:42:02 -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=YxIbv2JZ/qV4zGXdFigX3S8ljfnrUEhn14Ys1aZ1tTUXEm8VYqpXbLen8V6PWdmX0a E1KPMLYLHXQTaNCWXtiwbrArQV7LeWFbU+EG84BCpcJgteiL6c+tG3fLF7sDwGzDfG3S r5hrWL8TSW7EFVfolYDnRo5v1syNLMimHqANOlQXZgKEVy9hu3vUcNELux9OWdB15Sox pEZaa+p/BXkx7IMyA0XmUFOGfe4MSjUg/7LDoHyIqRjQppiMSyORcYeBWw08mDINHECt mKMRs/P6jP83P3rj2rhk01YJ0AVD+WaIOHBRq+aF0M4Glu+TVEtCF0AwjpAyhvn6MJNs kr0Q== 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=nFs326zMdkAUM9XEFBuWR47KgFk5T+//PW8smStcqfBEyI0XLbKvV9cWHqQkjgIxD/ slUtfPStbK/oAckF3iXyHEKQC7KbcQFp6aLAxgBL3CSiAdbWwsgaLiXoSq2/lPsfVTG6 q8aZ3m2knd8h5Ca2K0pscaQ7Wp1VKBCgbe7126tUzJdpeBPD9KDlPjKkgnO9GTRYGIvi u61euLQOXR+mCGEqvjpfSawWir4IOikaL8SOOXhKMJDPFmHX8cOh2H7/ZSsyo+GlZTrG IsQL4Edo+l88HOxwZY+HUtyl7Z2HuMP8YnGgWa0RlqrZmAjmZifbjjxcPhP/qDdHdLPX Seqw== X-Gm-Message-State: AOAM532OV4hq6YcfPK5JFDDsx+TN1ol4l7nlhuaKOUY5cUQJzhRZnR8M SHYJFgl92dYVopJ6glVNA7szF9UFlmU1wvn3 X-Google-Smtp-Source: ABdhPJyo0C2bPxvDzikWja0CkQYEzL9V2i5cKHIqhrS1fyoan+b+6pCwJnsUWRVvUkKXYAqE+QHiD+IlNohOm2Al X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:c583:: with SMTP id a3mr12947974qvj.15.1610732520689; Fri, 15 Jan 2021 09:42:00 -0800 (PST) Date: Fri, 15 Jan 2021 18:41:52 +0100 In-Reply-To: Message-Id: <093428b5d2ca8b507f4a79f92f9929b35f7fada7.1610731872.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH v3 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-20210115_124204_120719_8FE7E729 X-CRM114-Status: GOOD ( 10.64 ) 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 */