From patchwork Tue Nov 27 16:55:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10700993 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 46639109C for ; Tue, 27 Nov 2018 16:57:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 313B82C425 for ; Tue, 27 Nov 2018 16:57:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24CC82C45A; Tue, 27 Nov 2018 16:57: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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4A6B2C425 for ; Tue, 27 Nov 2018 16:57:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731430AbeK1Dyt (ORCPT ); Tue, 27 Nov 2018 22:54:49 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34517 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731441AbeK1Dys (ORCPT ); Tue, 27 Nov 2018 22:54:48 -0500 Received: by mail-wr1-f67.google.com with SMTP id j2so23474018wrw.1 for ; Tue, 27 Nov 2018 08:56:17 -0800 (PST) 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=cdKIYS87jEKsGaVGv0J/kyzmIxkse0BLBOe4/s6kF2g=; b=Ip5ogpaHKgzTpQygvmjooBMBVAtgRQRl+qgkAzJ7PDkUUpZM+3enXRCKJyUfAgUpE2 KN4RrLzeJzOlxK/NsObxYkCP+bixblO+FW6Kw8UNmAe67lAywwzxntNPQRi2tWP/U1Nv LDacTNsQuT1QzFPoYQfPMDS7CAGKpR6YYaA9G48zPxMzb8HczWqI6KI9Jw5GL5v4+IIF bjmifMvo2LAjKTHeBt10/F+/nr5I2kCBQsXpc0Va3VG3isKuzUhCiZMtkIYhODra3bQw lH/pUxLW+O25D3hQXEqFG11Y2SK/POzwZxDFO/ZXGOESU2l6kT/8Hbc/gMs22CZbK1Gu AlPQ== 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=cdKIYS87jEKsGaVGv0J/kyzmIxkse0BLBOe4/s6kF2g=; b=VNm5G9DAJDng5HKFwE5ZkZMAhZ55N4bkvs0BTKMYqZfGMePHoIgrf0LUvcv+0Z2/1y 1HPqgSwL9gyXLA6h0oAVFHwe9P8wudRnQJcA6X6+wB9o/kl2zIgCeum1ylItQE1Hlp9Y tFccXiCT8sAktle4wZ6UzYZk1kXYgjHExeAzJe4C77Zow4MUaR6N+G6wNTuKIDNbLgZ7 ulrT4+sIaxVtt0DiA+Mo/6gI2RX2Tbi2j0gQMO+dDr2ChklVvSkbxPmxbwqdBiKXsK8a FbfzAH8amylSaosC2tSAsfWEHbm+GaLkgxDNoK903jN4vUEXu5IdeSEUk6IciCCp+RRX 7BnA== X-Gm-Message-State: AA+aEWYm8hnZLMYzecWlNt3HgUgoTiPDDixUmWtsS5QnzvT28PsWuSrH Iz7UGhQt06Mhh6ap/uw7nuDeAA== X-Google-Smtp-Source: AFSGD/Va46vaty03/ntt8AicD2YvJXz8QAHtsdGhxXNOFGp6Fe24s3POR4AZg6sU6IkJKiYDLbbUeg== X-Received: by 2002:adf:fd87:: with SMTP id d7mr27062120wrr.74.1543337776184; Tue, 27 Nov 2018 08:56:16 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:3180:41f8:3010:ff61]) by smtp.gmail.com with ESMTPSA id k73sm6383099wmd.36.2018.11.27.08.56.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:56:15 -0800 (PST) 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 v12 15/25] kasan, mm: perform untagged pointers comparison in krealloc Date: Tue, 27 Nov 2018 17:55:33 +0100 Message-Id: <5045db8a8e249a1eda3199b952120035eacb3bd4.1543337629.git.andreyknvl@google.com> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.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. Tag-based KASAN 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. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov 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 5f3504e26d4c..5aabcbd32d82 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1534,7 +1534,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 && kasan_reset_tag(p) != kasan_reset_tag(ret)) kfree(p); return ret;