Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp785905imm; Fri, 21 Sep 2018 08:16:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYU8iGM7cKVZn//rW1IwharsUcY/RJWyYW0QnAunTwHiWNFFVu9FvCaQiYkthzM8KZ323yY X-Received: by 2002:a62:ba0b:: with SMTP id k11-v6mr47302688pff.171.1537542973207; Fri, 21 Sep 2018 08:16:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537542973; cv=none; d=google.com; s=arc-20160816; b=yz8TNJm4i5R5vng3vKc4/yAdIwjHBe1RrQwLeKbFAykv+sz5pfDrI11CMW2Nx2eh45 EQXRYktuNOwKwZ+enBTQLtwB9xV75TP7KtmVkvIKWYm1smpfMikqPEaRB91z2ASFlnrM pMlmLx1uGWNqlLHalyQ1ClUgTDqhVnpVKHdGN99ygnRmoPPtV9M/TbbZeI+M2GkVH6Aq 8v8t6FKnCA35kxCHGJL3/wN0VK3EdkWfbaijNwdfXWPi1I8pQyC9RnheyosOWbvpTJRp PPu6lJQ8iA88vJJujLfGd90HpqTq1LXY27EtpZIVIgo/Rg0Fj596iW6vbO1E7mheZpOT A6pA== 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=vP7c768qnCzMOxVQ3loi78vrT7BMbKGxJOBnuhTzi5A=; b=gevW/kVBf08D0Lu1aV4mHaL8j2Tiu+39SXzDiReuL3OmqjVZjT+p7HcSg9mPFJhRci 5c6jvbjjedwvrGEhZjSFtBvFL8tFYtFxQpjnO+TsfnZIRBiiA6nG4M3BSndCpXdaKdMw T7O5u3HSACtEV7WpHLNJxkqLIGc53tPoYSZC/GiRNp8xhn4wOCvdugRVZdZFYrpwelCk Muin5r0+9FPgPKtbihIuMxikID+nIJNvSXZ0zq5K0rV0vTV5YpLsrIYfqDKdFhA7Wfjj 0WjwoyoerXayI5Pz0an9Qoly2JYl2H4u29Yy7/ra4t1laYgw20PN+rEckaHAewUXMc0x rjjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RLE1rsoz; 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 b13-v6si26979813pgh.255.2018.09.21.08.15.47; Fri, 21 Sep 2018 08:16:13 -0700 (PDT) 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=RLE1rsoz; 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 S2391045AbeIUVDa (ORCPT + 99 others); Fri, 21 Sep 2018 17:03:30 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:33841 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390783AbeIUVD3 (ORCPT ); Fri, 21 Sep 2018 17:03:29 -0400 Received: by mail-wr1-f65.google.com with SMTP id t15so5312960wrx.1 for ; Fri, 21 Sep 2018 08:14:09 -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=vP7c768qnCzMOxVQ3loi78vrT7BMbKGxJOBnuhTzi5A=; b=RLE1rsozSV0zZ0sOdztgxYnq2Tug9v/n8R1sOEFvbh9GcH/MGsLOsDgt9HjYx+oyvh zfPs40puTwCQKCzPmSYjvtiGjJ2q3aiQvCVQEP6VTWXLmlVaEma8hlLfst73Peo5eRfY ZA/N/WdN7PXmdj+Cimt2jW3x7vxdaTqVU7z3ZaZfH/zthxecXN9c24SqSkGUDQrOjwZT DyxBJokdab+lSvQ6ty/N60UryhF3VIyRtRwxpjr+yQDySQ1dHAiPdnkCaK1Z5CqHhU2c ijfMHIArKRoyTAPwQjUJWykxdjrdQOqHpTDKFNd/ODybrDvxkRHAAbNGxrPJzAS8oCR5 ZYoQ== 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=vP7c768qnCzMOxVQ3loi78vrT7BMbKGxJOBnuhTzi5A=; b=RdmozswfthtAKzEGk5zn+WvUEdwfsIGQ2CWedwPK6qmKUCWAZFfgv5dDMfrBGgucaA 2fQd/8RaS/KofLyJIAH+rRHTD9rF/5Lj1yHDQqLc/demtI8oFDYSC/2zM+p+h6tHmKbx HVuLij3Bguz3cnHT/RHbeOmjAiAUKVqlZ4UZgkPCat0Uc5yafGmnIskAEuUcOF583Nh/ e/zQNKA9OUihHFevertQZsJUPR1NPbIVMWgO+z+gH5XZGMRMKbJhE96ggYIjhI42pHKj jeMy/27TPhN4w2zzYwwKWPhChQL8PsLw+oo0v8IOqgDdc/ULhwlvu1uTLgjjk+Q6OSai Br7w== X-Gm-Message-State: APzg51ACvYsO2445rH+dzXY/VJVI4hmxgcyEAXdFLEJihFb8nD1tcnnc 8p4buEXWpNq+H0d1iEIYaM2rTg== X-Received: by 2002:adf:bc44:: with SMTP id a4-v6mr40096556wrh.255.1537542849011; Fri, 21 Sep 2018 08:14:09 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id e7-v6sm27990271wru.46.2018.09.21.08.14.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 08:14:08 -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 v9 13/20] kasan, mm: perform untagged pointers comparison in krealloc Date: Fri, 21 Sep 2018 17:13:35 +0200 Message-Id: <77d6321d5117c8b8e2267a707b693a6eb67ea17c.1537542735.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.444.g18242da7ef-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. 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 3abfa0f86118..221c1be3f45f 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 && kasan_reset_tag(p) != kasan_reset_tag(ret)) kfree(p); return ret; -- 2.19.0.444.g18242da7ef-goog