Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp466167imm; Wed, 29 Aug 2018 04:37:10 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbtXtH9Cg8gsOuBZg0wgQxEht5oDM/QcX6UAR3R6toiUSz0S4F6EE25GqvU4yQm+Ru+tDTd X-Received: by 2002:a65:5b48:: with SMTP id y8-v6mr5455351pgr.125.1535542630917; Wed, 29 Aug 2018 04:37:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535542630; cv=none; d=google.com; s=arc-20160816; b=CfkwEJkJxh3dMocfClon1+DbS9CpGW5vVd3BcG/g1JLLkAuEZPFsXsZkpFVJkS4uxG hxUMXG8CHpU977YL12FR/8EB/15R8MgOVp9qbVKRRWqpI0BYP0lWJKb02ssSds4VhBS7 q9aRS01IybusTsTtxFSQK/ZY0NfDO8A5dq6w/nG2RiJTMmetVQ7tJjGrM0sLJSq5jc6L u+B/J2D3NRYBmeJkSc7TcaVgnhBXpGF7nFodlgbI3V5zB3Rk1XkNLjBKnnTJxifqilbq DRd1DPOSxVWIlW3WHhfGu2Z9haIyvhz06BoSk01D7cvVQAOGKGZ7ADGyoduHvT7NzzmF Ny7A== 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:arc-authentication-results; bh=WeSMiuMtzDEN1FdWmqPLXOd7CyZ+jfvYb8JwPl6GEEQ=; b=pwW67SPDJFDs7XwgPXMbvrSARY3QJD429cRtSx/RKFL0BE829IG1x8y6GX4OkJLuCl BSXwmrZkZehGO7M8tKs3QDKS0SvgVppL/wAud2JE4hWHoRN71Ijxxk4wolSVk4Ztfy6a 6ngewHZSAQJs5TDmjvoYrqcNyU726lohbxxro7U4yL1LOi6cBMmv1/JltDSfIqk0tRat hAyNCKRCf9hOG1JivBpkSCOIpi06LM3qdSICd/rr38DQSQql4W6K2SDPswysRZGWbWUz 01fNT+bYNjbWFKwxG39BBB+dFQy9qRa8imRRshnfFgWsLeeuTCd+8XeRE6OXwsWVdkx6 iTdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=DB2fTUZP; 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 g6-v6si3284510pfh.346.2018.08.29.04.36.55; Wed, 29 Aug 2018 04:37:10 -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=DB2fTUZP; 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 S1728624AbeH2PcQ (ORCPT + 99 others); Wed, 29 Aug 2018 11:32:16 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:38200 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728590AbeH2PcP (ORCPT ); Wed, 29 Aug 2018 11:32:15 -0400 Received: by mail-wm0-f68.google.com with SMTP id t25-v6so5154209wmi.3 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=ZREFtjEXTfHHKM6T4a+GRSMwRHTdIMg3iFIMEXgsQg3JtzRqLLJWKbsFI3BByPr3K8 YimuWMnOzVORbGJaWp4q4Q1Cm9wtO03P3X3SGtJUBjEasdO+1dh6jHd5Wg6RWL/4ocmy givnLpXZu+gWLi1myt8ESftR5aezHSKJCRa5Pf4pZMbOVxBCsGEHh7K4kx35Z9adoboN hJoLQkAVajOMBswcvx3YKF5mdIfdsxEPLMA5xpX9V2TloDhpAsHmHxUfFLVTmUhZMm9G StZBFaebLA17Z67X/8dGE5P8XkK2l6lS69uwsGZxOdwMHq514VsUUDGomaHqS2PehSRn TgGg== X-Gm-Message-State: APzg51CjuPb8zpfQEbppsCqaEuJEvW/fFAPRCMzs74GVClAba3BQxGK7 wzxUeR58YTt0V5IweQrPcQnIRg== 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 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. 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; -- 2.19.0.rc0.228.g281dcd1b4d0-goog