From patchwork Wed Jun 20 17:39:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10478249 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 64F3660383 for ; Wed, 20 Jun 2018 17:40:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FA9328D75 for ; Wed, 20 Jun 2018 17:40:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4419728E08; Wed, 20 Jun 2018 17:40:43 +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=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D91C528D75 for ; Wed, 20 Jun 2018 17:40:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C0156B026F; Wed, 20 Jun 2018 13:40:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 770D66B0270; Wed, 20 Jun 2018 13:40:25 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63A7F6B0271; Wed, 20 Jun 2018 13:40:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr0-f199.google.com (mail-wr0-f199.google.com [209.85.128.199]) by kanga.kvack.org (Postfix) with ESMTP id 009556B026F for ; Wed, 20 Jun 2018 13:40:25 -0400 (EDT) Received: by mail-wr0-f199.google.com with SMTP id j8-v6so238460wrh.18 for ; Wed, 20 Jun 2018 10:40:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=w0KS5wF5BL6rD0Y4f1kcghkQJh+byDC5CHCPIBvVtCQ=; b=SFbP9cnzM8imMSJ6+D5OeiUDkm9WW9qXb1f0rm5Sp8FoxsZOgHAr4uEzEaZFLF7Isb 0bvAu4vBHqt8AffjFftG9HxP9imRYMbRbgWV0d5BeqDKFWppswGd6pBgDb6HHSqdft6P Yci62Nw34OqxfJUkBoaxJT83ivhzF+vE44Ggw3E+eQyGVfTDb5jTqIb6pzp1VMxXxKTF oNv/1rv1tQq5q2G3qGzojjHrhDpvl8HeIid4wBQBuMKHKVgAJGLOBmQIktgSSn8EX+bx 42n/KpAiuWS/fXaAUrQrCeNDUE/7SwRnAz4DT5H3Bu1vbHlO6lrKc04gs8KtEPcbKHHG VGEA== X-Gm-Message-State: APt69E14sL6FeyuuyyfInOYQqic+gf7PEHfshFd4pYG31A5B17klTOuJ oN+XNmItg72/v1Y3Dfw4paWnLLXjD42zvUzqxLJWkklX7ZqsmFg842BimHGU8ncb+O65ybT1C7a 3FP5rTNahkQD6dHAVU4yyB+Q0qx1na2yatTNOhnOatVDAEgLhXTMqndN4dzXxDgCebCO01Yp8ao cfTXjzbcB94zelOkXUg+gF0gsViJjWxnsli4k9/noR/BuHNF3Exy1oEGgtsyujWj3UbDdSpHn2i jNQhZvZtjxl4ZpmXLiCg0ohbhtABR52iX6XjQv+f6KwnH575fLHW3zvXbvGF9rO1Ij9yQHUDwYV IB1t1XCdEJ0uxpBzcDv6opj4ot+GN+UvNVmaS04Op9Si61zaJyEQWco61rPZ3JBCCL2Vojj4bek + X-Received: by 2002:adf:ac37:: with SMTP id v52-v6mr19150020wrc.56.1529516424527; Wed, 20 Jun 2018 10:40:24 -0700 (PDT) X-Received: by 2002:adf:ac37:: with SMTP id v52-v6mr19149992wrc.56.1529516423847; Wed, 20 Jun 2018 10:40:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529516423; cv=none; d=google.com; s=arc-20160816; b=KU0AbmsvEApVa6xRUsWBB70c1dLvOZJ86VIbPJVGH+IujKtNbkmxqQFclnX3NOZYMO 4fyoWv0KPTZ+ko5E92jCDArpT6MXVuKOM84UOGXWuVyPqWGEyhZKfGmNzN8I/Pyr6WhC jpafEbe14HP6vLPVItH2D1vR6dlMrPx266ykJNc+KFSxLPmkBtFI2iAbF6L1kCQ9ZA2h h2V6CPMs5cSsNOP2G8kq656AbSsUshZRqicVreBi6JnXQyGXsYxwXxoY4+SOuGTMIGtM KzUmN+j1GNYpSGQSSC4283LUgdQYIghY9co9hgWTAODDuZEw69693RV3v5wID2xtNUfQ Bm2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=w0KS5wF5BL6rD0Y4f1kcghkQJh+byDC5CHCPIBvVtCQ=; b=JHUWslSPcAyUw9y1v0EqVrXj72rTpaKWNuEGkedynbD/6ktzoPEJky1wTVmbrPevso hT+3yHqA+ULoP6lbfaxcUs85FsCs2uSV4/xhYJMYNMtGbannZqoIHb+IdcZtsOFUHx50 HqD93mF8QSu+kq9Pvkl7Zta7SvVHupXCZyjxa9Dxwo3xsi+JyrEoR47pf/0TOQ7T9FlI ovzvLcYEde7ozTcK3Fjq7qvBnPter26m42kiOjgZFovnnY99eIVhPxGwWHYjrlv4KjOe Kmc6C3gDg562/IBYf1NxTn/toRvIXc2J286sOo8TJGMebZmTK0+LGNLchFmgkcXITaHS waig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oB65+o0j; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h128-v6sor1068172wmf.86.2018.06.20.10.40.23 for (Google Transport Security); Wed, 20 Jun 2018 10:40:23 -0700 (PDT) Received-SPF: pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oB65+o0j; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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; bh=w0KS5wF5BL6rD0Y4f1kcghkQJh+byDC5CHCPIBvVtCQ=; b=oB65+o0jQ6qB2W2699FbtW2XW66vGi/Teqj7sIvX27wm2wTSHZ3YDvMGRf+qxaxnsl dOr8z4/U5995KND4N0UtgUPJa5qqlmqKZjtslOlip+RRCV4rRSig29xMZFtKdKySe6QK idgHT4El7SEtMLxZLiXbVYVFNWkC3yclBl7DF46d5gK/D6YikGiZBxc4hMUrsQ33N9to drAoTWViBkbS5eVZlCFOW43LVfI7eTo2dI+h+lmXLFV93EiqsJq6e/NhtmUBqTg+kSaX Ibcn+BAL2vAM6qg3eKwkM9loUGopvD4Ixi4rrgwOQ5L1l/vxdZHj7rB5HDFnegO/Yj2d ZP/A== X-Google-Smtp-Source: ADUXVKIHy452yLplRLjZDKj8sDFzIOaOQhbaOdQUSN2hzmJutj4WX2Ro1xrWueNxZDkgOiWF/zqi1g== X-Received: by 2002:a1c:dcd:: with SMTP id 196-v6mr2542897wmn.131.1529516423292; Wed, 20 Jun 2018 10:40:23 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id f18-v6sm4388598wro.1.2018.06.20.10.40.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 10:40:22 -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 , Andrey Konovalov Subject: [PATCH v3 10/17] khwasan, mm: perform untagged pointers comparison in krealloc Date: Wed, 20 Jun 2018 19:39:56 +0200 Message-Id: <6ab2ac0b6a7d12d2a6616e847732305dde544a99.1529515183.git.andreyknvl@google.com> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: References: X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 c279b52c7565..7746d2ef5d45 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1509,7 +1509,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;