From patchwork Thu Aug 9 19:21:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10561747 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E4781390 for ; Thu, 9 Aug 2018 19:21:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F5232B92A for ; Thu, 9 Aug 2018 19:21:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D1102B948; Thu, 9 Aug 2018 19:21:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B51E52B94C for ; Thu, 9 Aug 2018 19:21:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9616B6B026F; Thu, 9 Aug 2018 15:21:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 915AF6B0270; Thu, 9 Aug 2018 15:21:35 -0400 (EDT) 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 7D91F6B0271; Thu, 9 Aug 2018 15:21:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by kanga.kvack.org (Postfix) with ESMTP id 1A9476B026F for ; Thu, 9 Aug 2018 15:21:35 -0400 (EDT) Received: by mail-wr1-f72.google.com with SMTP id f13-v6so5253094wru.5 for ; Thu, 09 Aug 2018 12:21:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=GuTtM2nMrJ4Dauv6kbJ/TNvmQSeA8vc6xmRa98AW0qs=; b=Wq33vInc1S43THA83/6CvNQpXnmeRV75FFu1OkR/xtmOX16+fuB+EZxQyKtqZFCGXr WZcpVJu1QDmJyFIQfQOrxAixY0o5mSQpgGegf5XG0iXV31uHGWl6zYqEDQ7H+dZ2+4L+ 53G9usqw+1lcL3qF0i+7yZaWtHNPmrkNJ5MyZh6vWl9THlF+6UhPDMr0jPIqwBRAnmNH EgtULUCVZerRkV3h3kFCzLscJx9FYzbDaB9s0yGpoFflOcVIsFGj98EK5uGQ2/10sEnW IM2tUbEDu8Xl3RYTireWNpbIF2RO3VKpCyTbeMZrMPMY9+1qeTLPTu8FVsvfjauY0uJS h9Fg== X-Gm-Message-State: AOUpUlEKCO5efcw8QcLLeuLErFrJGbSPEEgPLnMVqENCwQOeAWqbtwUG DHq8q08P4WebzYOaWE4F0zReaTeB2s8hT/q2VBmJc2IDh0gK8SijpZyp4xTC/7Xhb/H1dIrO7pv wCji7BDH3+zRuRVqFk3E2g6b0c1Zb6nmw39aIJENEDcFJovOMo9ztWmLK7VUA3xww6K3K1vwqIN igqHnGRfmSTDftgc4HDTIGOoNlWFQeJvYn2uAb+mBSQBItm14OJtP13aYnfRyd66fxYYHRtnoZL wAmYOEOR4oNQY3Slb6b5u+hsYW29KLxfuK0dx7TCMT00u9GeuPrPIyyWxePunZ07TV65CtJp7vX 7WakC39OjREzx/konZVgfw2RGwLd13oXVI9+k03/TLh/1fsJyPI7w+xcpwgbm7s/dOlXbP1VO6B b X-Received: by 2002:a1c:6c14:: with SMTP id h20-v6mr1339742wmc.138.1533842494596; Thu, 09 Aug 2018 12:21:34 -0700 (PDT) X-Received: by 2002:a1c:6c14:: with SMTP id h20-v6mr1339716wmc.138.1533842493869; Thu, 09 Aug 2018 12:21:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533842493; cv=none; d=google.com; s=arc-20160816; b=T3EU/VUVa/cYNQ+qkpif1bkRgrbp661+WTp5iljEOBlfSs6NRZenLiptlub9mrr63y 7i45Lz0AZ2RbB5oEaB8PT3qsyeaH/mtuKP9pIwrIpa8ApfLreYYeEmaG9JHXiJWOVMuz 7SYhu2pyg3imgoSE8zXb93yXasshpsPcuX4bLc9NwE/mqEjuTLPe3sNZOpFKz8EjdnnS IYTEO6+JOG/sEJfGgYcV5seh+hPud04L2K4XiSYkUZG/XKXrerTmP5rGCwo/zmj8ARwz 2kEsPPaNZdvIVht/rCog7+LZV5TD831BbpAgAIs1J8U0tm0uep7Wv1Sw3r1l+BxqcgfP jNRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=GuTtM2nMrJ4Dauv6kbJ/TNvmQSeA8vc6xmRa98AW0qs=; b=0/Q/i98N5pSW1v3E+70EmQj/xfl7Xb1k3/PAJl5fOJjPFyxt8E1ktyMCI5ZiMaV9Mh u1XE9Sxx7+bxoGQ99SupK8K/n+6y50Mdo0g8Agd3nGliTco2FblZKoZVFsPBzeL9JYCe hhY4ssps/hMAlRsr5Wru3M6zPQvFT5zgILOW4Q59AozIfukNvypl7G5dQ6yW2jcTXc8U 1gHSVRBloZx/8FXgo7JHiWS9jtf84NetoOG0UjoLHB+9KoGp8yL2WAkMsoumFy8aw+cz thtA7P63D6X8i1LogLsbb+4xFMLAR6rQNvkXhawpJeHEiipaGwv3UuWVLOy6ec/SVhgg hLvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=S86C41Sx; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id e17-v6sor3091807wri.46.2018.08.09.12.21.33 for (Google Transport Security); Thu, 09 Aug 2018 12:21:33 -0700 (PDT) Received-SPF: pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=S86C41Sx; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GuTtM2nMrJ4Dauv6kbJ/TNvmQSeA8vc6xmRa98AW0qs=; b=S86C41SxOkkA8LBqFkpGV082ZyZNGC5QXHiWw3T1sDHhydoGXq5vi07VfyMKChS7Sv Iz5d45gyPejwEm//MqYruIpmrVBNH48A3qms4bWpdTCqCleD9znCNyEiox0DrAuzXVNg RmyODypNQp4LL9JXBxYdGfunCTrPLSe2taxfSQavGRSj1pwjmn8u6GTECTagwyUTHx9X s1hfaOhM086GaejmBTAL5KQbzL4Z7liCLMyQkqZQeXkNkfu4Cn38T7tpr8Av/auJ2rj4 4k/Bv3rIHlS8YHxntefOQYqOaUepl2oJX4KlBAZWMyTy+fUp8E9uyScz3vDUpmWoEMCI Is9w== X-Google-Smtp-Source: AA+uWPxhKq2oJvxj9GKtDLnX44F7dLpq6UJjkmFDNe3axY/KVJQUX9aqWFA6v9GYuLkDRiiBufCDGg== X-Received: by 2002:a5d:4007:: with SMTP id n7-v6mr2348121wrp.258.1533842493247; Thu, 09 Aug 2018 12:21:33 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id o14-v6sm14738797wmd.35.2018.08.09.12.21.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 12:21:32 -0700 (PDT) From: Andrey Konovalov To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Catalin Marinas , Will Deacon , Christoph Lameter , Andrew Morton , Mark Rutland , Nick Desaulniers , Marc Zyngier , Dave Martin , Ard Biesheuvel , "Eric W . Biederman" , Ingo Molnar , Paul Lawrence , Geert Uytterhoeven , Arnd Bergmann , "Kirill A . Shutemov" , Greg Kroah-Hartman , Kate Stewart , Mike Rapoport , kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sparse@vger.kernel.org, linux-mm@kvack.org, linux-kbuild@vger.kernel.org Cc: Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Jann Horn , Mark Brand , Chintan Pandya , Vishwath Mohan , Andrey Konovalov Subject: [PATCH v5 11/18] khwasan, mm: perform untagged pointers comparison in krealloc Date: Thu, 9 Aug 2018 21:21:03 +0200 Message-Id: <3fbf2a591009f1b9743e82a51ec09019eb054c10.1533842385.git.andreyknvl@google.com> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog In-Reply-To: References: MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The krealloc function checks where the same buffer was reused or a new one allocated by comparing kernel pointers. KHWASAN changes memory tag on the krealloc'ed chunk of memory and therefore also changes the pointer tag of the returned pointer. Therefore we need to perform comparison on untagged (with tags reset) pointers to check whether it's the same memory region or not. Signed-off-by: Andrey Konovalov --- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index a99a1feb52c4..e17ed1573d08 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1513,7 +1513,7 @@ void *krealloc(const void *p, size_t new_size, gfp_t flags) } ret = __do_krealloc(p, new_size, flags); - if (ret && p != ret) + if (ret && khwasan_reset_tag(p) != khwasan_reset_tag(ret)) kfree(p); return ret;