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: 10561825 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 6D7E61390 for ; Thu, 9 Aug 2018 19:23:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A56C2B904 for ; Thu, 9 Aug 2018 19:23:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D3722B911; Thu, 9 Aug 2018 19:23:40 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E7E362B904 for ; Thu, 9 Aug 2018 19:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ib9FfsLftYbSAzTBNMhzSPGmTXjOYO9k7wMuUjI0RgI=; b=akQkCJxEYChu9T PGZP04KgnTT74f4KJVIuzI54qkGoJEd2KXx5Nf+slxdWbwapfZK4JjO7gqvznDwnxrzwbV2iX9mx1 BLcOGAphsk1c4YO+xvywbQNGXBcSS2Qc6/gWPSteTWuxyMVniKQKlQ+XkRv8aB1IpSZ/6tUQQBfil z32GPmsUBd6lq3wPym8BmyM1TVYebZvvDnVFN1/AayDrvAGqsXB1bn6YCiOpki10gYm8Z48QUrkR6 9AUq8Su/WLXoH3EDh4CgKNZXLwGvseOk9VOjZrPoOunhGW6PS4UwqN0muggW8UAzCSguOcnrsMreV Q+xBRzt6yeUfBDhRYOoA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fnqX4-0002cK-3i; Thu, 09 Aug 2018 19:23:38 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fnqV8-0000Ax-Hy for linux-arm-kernel@lists.infradead.org; Thu, 09 Aug 2018 19:21:44 +0000 Received: by mail-wr1-x444.google.com with SMTP id c13-v6so6117094wrt.1 for ; Thu, 09 Aug 2018 12:21:34 -0700 (PDT) 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-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:in-reply-to :references:mime-version:content-transfer-encoding; bh=GuTtM2nMrJ4Dauv6kbJ/TNvmQSeA8vc6xmRa98AW0qs=; b=bPfWmz9c33DyJobtoaC/IFCxPp17W9xvVcTsiismWAWI9Qy36dyLdfk2dSBNFPmr7R 2FHWzJ7wXPpLuQVzSUBTkZcKfN49JKpkQ2he+HhjHv9AaUQy2ZIz9eEHkJI2hf7hEbR9 XdK4TKTKw0DumbOZTsWZRODYg2bd+nYIq6fWPvS7qbHdfGYr9KKNrrr8eTkqGcKxU51H 318jVpD1/uZTB3kZS2iTmDSEDjTsXeFc7V8W8d6epdyyXxhUxQPp7+/FbCBXAtqZkcCc MBSqsvcX4U4Q4OXx2OMEsaDuAlTiSz182T1qV8s9pfaTZjWZX6gVrL42QJT9e2pixc8X 7kSg== X-Gm-Message-State: AOUpUlHeemCvDQqc0Gvb1/5/zK7jgS1HG6k0znhQaL5wD7z6fAP9K2B/ YTYaeR/bLaKzZpEG6mdV8Fnk2g== 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180809_122138_925327_EFDC7B26 X-CRM114-Status: GOOD ( 14.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vishwath Mohan , Chintan Pandya , Jacob Bramley , Jann Horn , Ruben Ayrapetyan , Andrey Konovalov , Lee Smith , Kostya Serebryany , Mark Brand , Ramana Radhakrishnan , Evgeniy Stepanov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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;