Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10634810imu; Thu, 6 Dec 2018 04:28:16 -0800 (PST) X-Google-Smtp-Source: AFSGD/VOvS4hJVOH/Pa3cw/AUKn0Fdy1mPJj1bCGCdZd2A7Ay4Nm/hepA7sFYEnqReAffqsR2lDL X-Received: by 2002:a62:4587:: with SMTP id n7mr27996511pfi.118.1544099296443; Thu, 06 Dec 2018 04:28:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544099296; cv=none; d=google.com; s=arc-20160816; b=JJiLrJeCABtV9LExPSDemxGmu5cPq/rUs0Va4qoBQ+UdXCo7OhYWs+uZ3nfntvVHtk Zrju5dsal4GnSJ/8UxjT22DXetqsZ8Ldp6INn7y5pr08yJ34yJh7HoAP2YlK3I9WjwT/ ncToC+joQqfDhs0EtmcXJQaUZiTG/B/ZvICfRu/1+iTWBS4uMeOh1vGVs9M67+jiD0Ck bo2V50lzISnCNPY4fnN8aOJyG3G+U9A0L9IvkEyta2ZD1oEQvkW7CfGl3CBskI35AglK z0xy+oF2XZHqdbNcvynIeavYf0nn2sJ1nT8hIobIfi6H3tmXKfSLWNubSTtqE+uk1r8L gBgg== 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=fxqgizsGn0AaIQnRQ33dQkRGCaY8UuAWu0B6VsH5hUQ=; b=iqM7EGQjYVzQWrm0dg+lzBJHrssl5fxEVWG4Grp+DTNXKWq+qT4j5hVLudEHhcXcvy SBmU0J5dBcR2Y7QjAqKLhK8Ju7e2hHFioSGxuUK0rx3xAlBES6Czqnyu77gKOfxibFKf wd84rk9t9rWbOEj0FdcqoInvwkwnkE3LF5/cIV73zai5zETf/4qV3ux8aoiBSO7FL9kU vxVZk8CNH2B6KstU1ht0XEhfVon2i12ZsCi8z7NBmxWYdynKBFtNEEJlM+WPeTqyHUoD JcBzbQxv5BYwahpo5/PQoSFJW59AdHR8pA1kOn7gnvoEzvxqv+OZWTeA01aZJckJbjkn y8NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ujk3SHMZ; 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 g11si204340plt.4.2018.12.06.04.27.59; Thu, 06 Dec 2018 04:28:16 -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=Ujk3SHMZ; 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 S1729817AbeLFM0c (ORCPT + 99 others); Thu, 6 Dec 2018 07:26:32 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:34677 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729714AbeLFMZO (ORCPT ); Thu, 6 Dec 2018 07:25:14 -0500 Received: by mail-wr1-f66.google.com with SMTP id j2so326676wrw.1 for ; Thu, 06 Dec 2018 04:25:13 -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=fxqgizsGn0AaIQnRQ33dQkRGCaY8UuAWu0B6VsH5hUQ=; b=Ujk3SHMZqV7n0tte5Uw8nokkp/oH0FlKFLsFxzElZe9Z0slbPJEAJExlirmXwEUB/j qeFI1DE4ncGLA0+FkTusmS35oYv/U8UXI/jfcSKa3QRtSlDZ5L5lHaiWfjgmPd4nFF/+ vGwiweNbXNO50gJDPLGhzJri8t+wJQe4o/ND+9KUuI2L26oBYQ8hULSaxQMaAnF/iqDX Hpv9wpz9cBx90ytQ87K72yusvxoLQs9ZuSGL0uO4fMjRQ9fR2bvdzrwnlroIA0fQeMGW 0wXe8PTBJ4EYtsNFcnsc8WZUW2aYYzJizcPd8EFhPQh0QD0nyqeteBzhl8XYpy7aMdWS egGA== 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=fxqgizsGn0AaIQnRQ33dQkRGCaY8UuAWu0B6VsH5hUQ=; b=tuvm05xoja2S/Ukmx3ktwjwUcdO9w+jIJuR/gZrb9aZkFDzaKdwxbCNvdUiiF1FEpb F4re3iJe9QwAJkw/IM8ZBTigM2V/17juf/NV6XLa6F0TJRg8d6Iq3ddejakyzHkzzMLd OXwBFh3tUdvqSzSf9vcEKOWDb34Fs89w0TRjdyCk1o6mviV04rXniJ3PZ11MVnG9Yv5F fxxnmgij/UcW1gxDiNAkuGfTdvTC43yZBE4Ilbi/KTunkkj44WOG+G1jzckGwNuJtCS1 4dYqfxOT8S7IsBMNUKvhITZXCAyee0/ZzlZyqdvXiol7tSgoZEt+Yc8VMt6NopF4+M21 VkFw== X-Gm-Message-State: AA+aEWas6mo6SSXirN8/vLX9YxCZocn5XBayb2Uvmv1d2JcMcyXECPOj ICkGih4cbbjS/k3x1ncWj6pODQ== X-Received: by 2002:adf:b783:: with SMTP id s3mr26257791wre.274.1544099113048; Thu, 06 Dec 2018 04:25:13 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:3180:41f8:3010:ff61]) by smtp.gmail.com with ESMTPSA id j8sm339988wrt.40.2018.12.06.04.25.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Dec 2018 04:25:12 -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 v13 15/25] kasan, mm: perform untagged pointers comparison in krealloc Date: Thu, 6 Dec 2018 13:24:33 +0100 Message-Id: <14f6190d7846186a3506cd66d82446646fe65090.1544099024.git.andreyknvl@google.com> X-Mailer: git-send-email 2.20.0.rc1.387.gf8505762e3-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.rc1.387.gf8505762e3-goog