From patchwork Tue May 8 17:20: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: 10386629 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 B7C7C602C2 for ; Tue, 8 May 2018 17:21:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A36F6290B3 for ; Tue, 8 May 2018 17:21:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96EAB290B9; Tue, 8 May 2018 17:21: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=-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 28310290B3 for ; Tue, 8 May 2018 17:21:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 251866B02D0; Tue, 8 May 2018 13:21:34 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 229146B02D1; Tue, 8 May 2018 13:21:34 -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 02D416B02D2; Tue, 8 May 2018 13:21:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f71.google.com (mail-wm0-f71.google.com [74.125.82.71]) by kanga.kvack.org (Postfix) with ESMTP id 9A66C6B02D0 for ; Tue, 8 May 2018 13:21:33 -0400 (EDT) Received: by mail-wm0-f71.google.com with SMTP id e74so3519707wmg.5 for ; Tue, 08 May 2018 10:21:33 -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:in-reply-to:references; bh=Vk6H7EqObGOe3OueMBY6mMglUBWPr45n5C13EM+GkZA=; b=BVNl5ckw0yEUwecpgN5KmJCfE+OqJG5cUDsMQv7CN4/xso0k39QX3uJ+GijOG/creB CDK4wB0uDM9e7ip21uyDjmEd2deneeg2eG/iZru5KO/0rMFRJ11nTDOElggRvj5uO/kN rtHsUaQ7b5MclyDoKYH/MvTKFnKK3KO75SI4yumMHh9Rk7Xz61bxqbYQbtDmKUKGnlmT XOqaWHyJmsDDrS2QbOQrp2C9YTeBqB4O69JICGTOuvPmnV6DpFSpFaBw0i4Ny52XqpGf K3Kgf1eXzw69m+snGLN4QoOIfNxqsoG/LnN0sbTVErZPR6vwNriSkHfsDYIl6bn8BR6e 0T9w== X-Gm-Message-State: ALQs6tBcnzQG22cLzJQrhmi8VsaXmk3OrmorHycdyfAKk662G8eWqfYi 7tXpGs8aeLn6QKxk9ooaYUbHF5Usfc7IiHwdX+QX2AibVg2yFbg840iNFw98HmdEVCinOKmjYFn 8tMOHIKE59gaS5hd+rU1VYYb1GRHVS/CfKvQ5sdSl7jvQ76NSe79fQDWoGVxGK9WMGYXMwLM8oI PmHJT5cGxhenPR8XdIxTRS5vOPo0pBlhjrAWsFdikuRkzriiSxdd3/rnXwIaDE9hCx90BOMtsoy FS/jlT11l3L/xFr4ZriX1gS23kz4bDlgIJSQKZyDrXRdLsmotUMduFCEkhFn2dOIBgSzNR0Yv9h B0194BVNp3zQne5neOQrfiqwhQoi0XwcJ6WTNAUNxbGq+JUJ2Vjuo2fr3r3UFvsYqNPwEWaj97a p X-Received: by 2002:adf:a925:: with SMTP id u34-v6mr37070857wrc.248.1525800093208; Tue, 08 May 2018 10:21:33 -0700 (PDT) X-Received: by 2002:adf:a925:: with SMTP id u34-v6mr37070801wrc.248.1525800092510; Tue, 08 May 2018 10:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525800092; cv=none; d=google.com; s=arc-20160816; b=A2sh1MpYtuXBsq4C3e26CfBHOdj1dhprePaPJpX/TctEbolhWZ/xSrRIDqhL6QF8iM 0qlcF9B2QIJKgiq7mrz5hVENeYV0Ti304mhiirevegeRLEvLk39ov5FPPOnR6deDx4Aj J4v76X2+2R1FOal9yxS8d1f9KAcvVfRs78GDiXL6TyTIboxOTHx6JCxuGqnyOx1tG7nM 60Ycfx2JSUQiLObeLUq0jLxJseSnbfW1gheWxA8UbclITezf81f5ALxJE6JdmMsbvUSI +dIYaULU31E0oM2J0uLSsbjNsPyGeuZ64C/99Rv6JfFn7QIeb36PUmDFgJQkJModOZKV Qk5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Vk6H7EqObGOe3OueMBY6mMglUBWPr45n5C13EM+GkZA=; b=ih18B1pyYqFHkx5cD4duouaeoly5qnvIn5iRB6DoLaXdKc7mxsQIR3c+xp7HPZOkvj R8jy2oViSgQQvXPn0/ui9plSlw8MGGVmpboeocClYZxMorYVl7/lpKq4pv5Xewwm3mvC Tg7tAKem2s0cUUu8gqmRYlbnXjMHUOy8+zWUU/ntzAh2DSHgKG8BjPvfsgyxZzkz/Hcg xO3rf97Rkh+Y+hfr+mQ0sjBj0EVGji/q07XuwkwZMiAP7e3yrg1KsCtsKfVMpgtnht7J 6Em3n8iso5CK7/mnRIalrc/EwYp5GbxTXwi6/dBlMEAYOqk3fTt5uQihIk9X7VI38fKd Iblw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=K1SQbcPc; 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 w16-v6sor11799477wrc.60.2018.05.08.10.21.32 for (Google Transport Security); Tue, 08 May 2018 10:21:32 -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=K1SQbcPc; 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 :in-reply-to:references; bh=Vk6H7EqObGOe3OueMBY6mMglUBWPr45n5C13EM+GkZA=; b=K1SQbcPc1powVnVjRmHx7O0K2XSWIFBFugaJIzaAyWMKtsi0FengU2kQBlpBY/F6p4 U7mQLZledTptUng/1YLdztAerOkhyV0b29uy7rQmuNbCrETkgva3d8cbjLZTDVwGMvyO fiPdqs0h4D/gnuC9EH288PWOX5OSMiqBRKPaY/DehVEPAIj43jRg7vg/dTtw9iKfp/f4 2aFREVBa3uirQMAiH1sRGcessNtH252Z9CaG1gL5efWwoS1X0FMfu1dXOEx2QxZ6Yg1F UR7XUO4t6IhgKU+Q3eB4OvwzfrD+cyzfMdC2MF0wcxYZ5YFXWTn1Z5PKG0tq1jY+y83T j20g== X-Google-Smtp-Source: AB8JxZqRWZSyHBNGwW9+VJuuuaXrydk8vbnqkQFIhjNBMBWFeV8mllDTquBhOCrTGK36NGRP5AFLSQ== X-Received: by 2002:adf:b509:: with SMTP id a9-v6mr2730855wrd.191.1525800091570; Tue, 08 May 2018 10:21:31 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id m134sm14178311wmg.4.2018.05.08.10.21.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 10:21:30 -0700 (PDT) From: Andrey Konovalov To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Jonathan Corbet , Catalin Marinas , Will Deacon , Christopher Li , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Masahiro Yamada , Michal Marek , Andrey Konovalov , Mark Rutland , Nick Desaulniers , Yury Norov , Marc Zyngier , Kristina Martsenko , Suzuki K Poulose , Punit Agrawal , Dave Martin , Ard Biesheuvel , James Morse , Michael Weiser , Julien Thierry , Tyler Baicar , "Eric W . Biederman" , Thomas Gleixner , Ingo Molnar , Kees Cook , Sandipan Das , David Woodhouse , Paul Lawrence , Herbert Xu , Josh Poimboeuf , Geert Uytterhoeven , Tom Lendacky , Arnd Bergmann , Dan Williams , Michal Hocko , Jan Kara , Ross Zwisler , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Matthew Wilcox , "Kirill A . Shutemov" , Souptick Joarder , Hugh Dickins , Davidlohr Bueso , Greg Kroah-Hartman , Philippe Ombredanne , Kate Stewart , Laura Abbott , Boris Brezillon , Vlastimil Babka , Pintu Agarwal , Doug Berger , Anshuman Khandual , Mike Rapoport , Mel Gorman , Pavel Tatashin , Tetsuo Handa , 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 , Kees Cook , Jann Horn , Mark Brand , Chintan Pandya Subject: [PATCH v1 10/16] khwasan, mm: perform untagged pointers comparison in krealloc Date: Tue, 8 May 2018 19:20:56 +0200 Message-Id: <94f6719e7e696977de00354f8201581a8f9108d3.1525798754.git.andreyknvl@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: References: 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 0582004351c4..451b094b8c5b 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1478,7 +1478,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;