From patchwork Tue Nov 6 17:30:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10670959 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 8827615E9 for ; Tue, 6 Nov 2018 17:31:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71E852ABBC for ; Tue, 6 Nov 2018 17:31:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FC912ABCC; Tue, 6 Nov 2018 17:31:37 +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 EA4E92ABD4 for ; Tue, 6 Nov 2018 17:31:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BD966B036B; Tue, 6 Nov 2018 12:31:07 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 26D406B036D; Tue, 6 Nov 2018 12:31:07 -0500 (EST) 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 099BC6B036E; Tue, 6 Nov 2018 12:31:07 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by kanga.kvack.org (Postfix) with ESMTP id AA52E6B036B for ; Tue, 6 Nov 2018 12:31:06 -0500 (EST) Received: by mail-wr1-f71.google.com with SMTP id v6-v6so11863912wri.23 for ; Tue, 06 Nov 2018 09:31:06 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=wyLKUPGn9jgKs5kyhcnEkFlESwFUwxhfNlag9MpDnKY=; b=s4aZPay+E6+uGdxO+wGYvtFaufgD7Z5MqbC3f45GUq75taGgzBL78jEpeshOhKofCi 6V4sTYbchHpbHSMp6bqYb0yBPuCigzjvuUojPQ4Qylc8aHYeFJWOTc/ID0lUVUexGXbL B2w/IFnS+hu1ACtmtMbc7LT2Wa2cAYeWdrLugd9mmnPCtFlj8sR/Bolsf7hBhhEjqTt3 4AR3Fs3j3HGGhTuIoOHLPaoPtueL/FvTn+UCS5e5QuNpQH5csSauD3IRc41xV96lufXc gXpgn7v4oH/Jaw/Hk3tGZ26HcXZI6r+5ZspJVoheOMXe5Ll8IU5YF7GCs4hkZvHzPNAi bSkA== X-Gm-Message-State: AGRZ1gJ6jt/PlR8RfB3wfp0PaNZIt+wlHiIpA1sNv5wroNOTdeUV2ceq Os9SRBMHWT21ByS78IgXafJBHf5KFrsKhV9dAltKFjDx6cmIgE9whnF9E/Lm2hjFp2nTv5PTDRn SZ4V1hCs1jtEvLbA45Jafo18gXz97oqpZFUOR4oFb1n3GmC1BGedFRTCdBP8z4ip8H+593iIEwl 3l/FIyCq3B8lxMoGsxbuelKJQpT06MdF1eRfbZG+hMi7cCnFuHfJajJY7NKk0fPn8PsxjBFGKkN SR+QSwWH75dAulUddC+1oWHuYOIgMVI4aAZy27QvReh7FqM4cmCfHPGeclVXPw4ifNKwFKf8viX YlIkx5qkKoqHRpi838CAgtMaXVzDTW2PAOS1I5XAwEhxF9iojK2xr/UnJvzd99XPfO9E0RSB1F0 W X-Received: by 2002:adf:c189:: with SMTP id x9-v6mr23755588wre.233.1541525465953; Tue, 06 Nov 2018 09:31:05 -0800 (PST) X-Received: by 2002:adf:c189:: with SMTP id x9-v6mr23755542wre.233.1541525465092; Tue, 06 Nov 2018 09:31:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541525465; cv=none; d=google.com; s=arc-20160816; b=EcFVi19syRpzx9QnwVmC9C7AUqZ80ioURuXdMs1bHd0AaRcfISvwU/M7SH5+JJNxlv bCkTZ/NumqIbVwcwsqWPXM5AkDfxwSgKvtnN6/tkBVCsMJV/lniQ6lF50W3yRvBxkIVU JiJK5IsIvujsLM+FjfxSAemersjvILbrHQIR4m+tEmTZcwbdj6luKgYSmEiy5ZJ7MAbO zTuSfIO6h7jaRW/X2JQtrOMbj8JIsusotJ3/RYAbNaWpDwQhQ4dxumN9UMpRPMKmrPEL lRkzT0f57t7VgqVk962aqJ0pOIV6S4L6XpVedba34ydw633EX3DsBb2lgEsTx45RB8VV oQOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=wyLKUPGn9jgKs5kyhcnEkFlESwFUwxhfNlag9MpDnKY=; b=XdHjl3tDADvoLC+64HanuWAs9IDb76lzQTjGu+d4XVXMZtst82YwUBU0ul191eGkdr H3p1O4XbXSmhhu1CK03jSf1v7jDUu9HEp9ucFbEj919dsjhj+5c57BtX7gozHIFhJEjz +4I5Bt+Somzf+4kVpjDWr5ZZ800iF8GcYQzKF7eYyNblGGc1EbjxcjN4nwvsZiTB7T1B zd0KaR0YFFU+NOdqX5OSKa51lUla5cGOIzFgb1Z/sjEi5oLuX4Kzkjgr9KvPKKLZX7wR RPmFZnw/xj+zUZEDiFitQts2djJxd/WCFTAxkYyYkyItVKfLE0cxVm10uv8x9TmQ6w75 vQuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NdZcOdV+; 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 62-v6sor8805677wra.51.2018.11.06.09.31.04 for (Google Transport Security); Tue, 06 Nov 2018 09:31:05 -0800 (PST) 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=NdZcOdV+; 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 :mime-version:content-transfer-encoding; bh=wyLKUPGn9jgKs5kyhcnEkFlESwFUwxhfNlag9MpDnKY=; b=NdZcOdV+SeQJsPz94m7H4XbZIwYUVU7yfboopa1Zjkyz1uIe2LlTLBqR71KPODjk4w w2i8lDUlVZAZkkOc9R+Q3ZJezDsbmPNngjH5GGihgainLZsCuwZov11A/67GWeqlJcfq +nbTxxtex/VSTC6mj0qA21CD7O1h+ebTAPCJNL2lovRDEHcZNUuJySqcFbS+ZbxwDr/E K2ifbpcrlmfB0NCeAVLhsJelIHCbITz8Q/LhoU36zDmoN+csn7I9AlcesdomO9yOLYsd khQiU+Km8JaWBY1mrboUqf+Qb5s/GZ9L6HQqsuN/RYVQLW821T971uEQ1HkkHYY5Jlsp V76w== X-Google-Smtp-Source: AJdET5d8EgWArhBW85rMDSm87h+TZuEVQo4IoirzvQvLb/UzVNBtYXRv1TEEXHRWUFUXNfkKIR1brQ== X-Received: by 2002:a5d:6551:: with SMTP id z17-v6mr20589467wrv.231.1541525464645; Tue, 06 Nov 2018 09:31:04 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id z17-v6sm16328416wrm.65.2018.11.06.09.31.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 09:31:03 -0800 (PST) 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 v10 14/22] kasan, mm: perform untagged pointers comparison in krealloc Date: Tue, 6 Nov 2018 18:30:29 +0100 Message-Id: <1d9612a508dd95248cc1cd3b4a4b332b4a198212.1541525354.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: References: MIME-Version: 1.0 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. Tag-based KASAN 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. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov 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 5f3504e26d4c..5aabcbd32d82 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1534,7 +1534,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 && kasan_reset_tag(p) != kasan_reset_tag(ret)) kfree(p); return ret;