From patchwork Wed Aug 29 11:35:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10579945 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 D71051709 for ; Wed, 29 Aug 2018 11:35:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C76672AA9C for ; Wed, 29 Aug 2018 11:35:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9EC92ABDF; Wed, 29 Aug 2018 11:35:50 +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=ham 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 6D4A02AA9C for ; Wed, 29 Aug 2018 11:35:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728625AbeH2PcQ (ORCPT ); Wed, 29 Aug 2018 11:32:16 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36289 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728591AbeH2PcP (ORCPT ); Wed, 29 Aug 2018 11:32:15 -0400 Received: by mail-wm0-f65.google.com with SMTP id j192-v6so5188591wmj.1 for ; Wed, 29 Aug 2018 04:35:46 -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=WeSMiuMtzDEN1FdWmqPLXOd7CyZ+jfvYb8JwPl6GEEQ=; b=DB2fTUZPwYG/vC54X0ylcYITM5VLrqYbpoKAgttKvxIgjM/CMpHyEfZop0XiAxCjAR SqefjUTWrUaMFbrzlRaCkfPP2ENFxVz4o+3GyKyWZfACMcIkY8BvkKjpZ5rLUNzQv+vC UaiuKzQpQaLSdmSwRMrFir9YX1tzVhMmHfnFRDWuVX9c7EM0JdeHcgrdRy8butdZgjsO O5jsznGZWbNwzg1Hwvpy4cG2lxNJ8pAsWYQXASFciem61/ZlgRxIf1J82I/AV/Gi5n/V efOWPmlesPVvERDd7ijRqLcvXF7OOC/l5jMPEgZPmfTjC7dW6V65A5vbC7e7im+oXG2d LbdQ== 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=WeSMiuMtzDEN1FdWmqPLXOd7CyZ+jfvYb8JwPl6GEEQ=; b=Z/nqfNVqYGIv+spuFDebRfO1cU9/NWDMGkqEfT8uq2owtPm7v/Hp5AWjT8zS9EUtMd 3wu7diswLekjj3z4i8NDmVHTMIxQhpiRPmeJyZ+pntVpdDFptadZNbox3iTTLrYfOrdt xnZ1bX66utwe9omz9AJV0CoYTlBO42atECnUVWgakUqLqZR520T2LOySBSpSPVa4uIqu Ho7XQ9FaMvl6dl7mflmTNsEDsEmDLcZ9SJUCsXID8AMmlY/euQDJ04DrRViu1VjLI+3h X5VuzuYpFjMCVnqPB07VD+UaHp1KphVVEmerGuNhKk6JHhwRtuWiT+78Pv2RZrkNK4T9 LsNA== X-Gm-Message-State: APzg51AgWd6J0c30c2iUd1vQtgxU94iD7WiHtuHvM/akbxF8Ml2gqg+K UucKs+7BMwrzmDU7PEDkcbMDnw== X-Google-Smtp-Source: ANB0Vdbc1gSJCzQt/c4lE4zyKdI4J/AL4sF1sTjGC2+4JWrxUIp67ZMN/Z0VxXD8BaXnDRSB0wO+UQ== X-Received: by 2002:a1c:200c:: with SMTP id g12-v6mr4128408wmg.102.1535542545044; Wed, 29 Aug 2018 04:35:45 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id s10-v6sm7800454wmd.22.2018.08.29.04.35.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Aug 2018 04:35:44 -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 v6 11/18] khwasan, mm: perform untagged pointers comparison in krealloc Date: Wed, 29 Aug 2018 13:35:15 +0200 Message-Id: X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-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. 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 3abfa0f86118..0d588dfebd7d 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;