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: 10580047 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 F0BD21709 for ; Wed, 29 Aug 2018 11:43:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC55129056 for ; Wed, 29 Aug 2018 11:43:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF5172944C; Wed, 29 Aug 2018 11:43:52 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5FA4529056 for ; Wed, 29 Aug 2018 11:43:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7rF/yiglBDHxi88L10njuVPy0IgWBuq450Bflw7G6vo=; b=s4UGN+RZSyCEeW AjWsAZhzDSxP3rGRJP5Z6DAJJI/ZZ//qkWhiNn3YfeeDh4fEhAdvj9N0eZOCOhWHxKyoDomRHN1wF sQlJTZ0MQxXYWOrzAvj9IkFEzb8ODNySD4pxSeHF/EhIM2Hqds7lmabFi3S+WzYWbOyVB7qnoMrFT 4+a3FbCFHAlNfjvfaJ/Qyz04xsP6um4ELcpHKSI2yO6h/m6h84wHjEVHWIQYyFSRogiBsRBNW2bde hZWuhQ7VP5CAt4Pe8ZUxZ/6eb7CtHiNvo/gOumZP3pWi78wyeVk6/yp2DgffxsyboX/w3gSPbjR3j 8MgwBpwlBaNvSmeUq2Kw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fuyst-0000dY-Qj; Wed, 29 Aug 2018 11:43:39 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fuylJ-0004aq-AO for linux-arm-kernel@lists.infradead.org; Wed, 29 Aug 2018 11:35:57 +0000 Received: by mail-wm0-x242.google.com with SMTP id n11-v6so5146240wmc.2 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=TF376aCig0hkigl117emDJRFeAAMIet9ZC9Wt1Vab3PlhYlPCQU3HUs3FR0IFTwtX3 9QdPCqu4tYm3TuAcBsiTxDJvzr4duM684ZmmseKMoxVvpNw5EEIHApn+rbRb6XOfGeiV mX1/OnaLv3RUTi9P8C/Yykx9d4jQLTuUNWuLREATkY0tirrDlzNftYWj9k8h5uPprLdx J9ZknL8pHQ43pZRXj6Wmv6/c+mgvUxs6INI9lcdp36Sb4sErel7biM7Qcx+kwyIAZXo0 sHSCGclQuW/FMsQZef4hBeLse4AD0KqAo7eAc3x4Hz7vXOEh45m0hGttPYr5KSisqP1k +jkQ== X-Gm-Message-State: APzg51DWk7EyIpDQ/r+yNJy5dA1QrmFIcIdyGHmZdmefZIOavkpC1tFX DddBqapw6MUk8wUduOEWzj+2XQ== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180829_043549_438485_800AC3C8 X-CRM114-Status: GOOD ( 13.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vishwath Mohan , Chintan Pandya , Jacob Bramley , Jann Horn , Ruben Ayrapetyan , Andrey Konovalov , Lee Smith , Kostya Serebryany , Mark Brand , Ramana Radhakrishnan , Evgeniy Stepanov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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;