Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp227459imu; Tue, 27 Nov 2018 11:27:19 -0800 (PST) X-Google-Smtp-Source: AFSGD/WmpWBgA1Q3+sZcicJYzFaufIxB/GMcYwCtOPKsjuA7GFDRevFXeAvlz6PwIptjzgU4u3Ek X-Received: by 2002:a17:902:1e9:: with SMTP id b96mr33890819plb.150.1543346839763; Tue, 27 Nov 2018 11:27:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543346839; cv=none; d=google.com; s=arc-20160816; b=EF7I5sY6+TL+G8f8acnNBmD7S7aPTGXmaYECEsEe2RXhfOxF7QpTK0+J9zcJv3798u dNJjShSP6jerEXZRQXYUq1rJVn0vDhiPW4dF7kYvZP5/z70bcKGtqPUTHIeLsJQpUTcO OVsLmvaL7KX/8fRPp5dzoU2T4JWixXjBUxhEhdb0Ye3reeyNMFYGZfENRPYRZvAEufGS gcg1JPb0GKrowahDiXWTE7mICDtLNW9yWvwOXvdhUOXEWetI4JySSIBsz+UfZwsT8C8B 1eXut0LUxcQOZ8rn+zrsz0d+GZpiu1MElDOGUD1SJcnu/6t7QaepF9JPE5jvLm2j216u +LwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cdKIYS87jEKsGaVGv0J/kyzmIxkse0BLBOe4/s6kF2g=; b=w90nvQnst+6Fi4H3o2oq/FXmpQpfKroVzoSKNebF0bJ6ugTUySIOhP3CcUdN8WG08x HXC+EvqVLcOOs0gfw3teLy8JJ+xqatiT1Olnpm0rjmxLbUbjzgjmoii/xLRMdLZjQ/pX oOb3c0VwXV5qJPv8iOczdrKD+8f3C+W0GhIDvDzSocpzcU9Tlcgji/2Q5hue8l3QwHt9 OLNfLMbuStFjjU32wa7dibBHh1mPx3QYsFszHURQfOmzUt8oSGRYR8ydLAqez+qFkyS2 pLWJ1ZPHfn3fEUcn1kRMDOifyljJO8kNMbRzovpX97tabQGvuuying9kEFBfs86tzP8V 94Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ip5ogpaH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g10si5027185plm.1.2018.11.27.11.27.04; Tue, 27 Nov 2018 11:27:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ip5ogpaH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731747AbeK1Dyu (ORCPT + 99 others); Tue, 27 Nov 2018 22:54:50 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:34515 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731498AbeK1Dys (ORCPT ); Tue, 27 Nov 2018 22:54:48 -0500 Received: by mail-wr1-f65.google.com with SMTP id j2so23474017wrw.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=DEECtBmUS1bTFD3XVqL4GPZd6G8UEZ8xxy182vqWyHFVkQ7G42SDxW2/AGuUcwCXCV 5lq2Zu9IvrUFA3fFyxeC96RTvtNtKhLWCjz/FVy8tUKBusYJ0dr+nHxtjMzIn0aHd9dz RjuiYozugCfpGuo/Zgkdes8TOX3Bx/V29srP15aRM5+haz3J70WbxQsCBtSUqajbuFdS tfOyftPYkpZztgVWwrQTF8bt9TsC3tgTYEdiBbkIGvPvhzQFE/R/hTKCcyVVEzbdIE/A qy4N8bvy0/Yv0Qtlur/KpsxtkslnYnY5lqiHnv0hNTh1TjuhF40DhVGMhtsN+jfez6gx J8sg== X-Gm-Message-State: AA+aEWZ2ojJUV0wCCgjeyMdit6YtyKP3TKdQz1u56CFshR2UvhAeBVVi Q+wT5QBXnWF3o/vYdx20ZDUdbA== 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.20.0.rc0.387.gc7a69e6b6c-goog