From patchwork Mon Nov 19 17:26:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10689105 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 5FCFD14E2 for ; Mon, 19 Nov 2018 17:28:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44DD129975 for ; Mon, 19 Nov 2018 17:28:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37E2029A0A; Mon, 19 Nov 2018 17:28:51 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E117129975 for ; Mon, 19 Nov 2018 17:28:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390639AbeKTDxO (ORCPT ); Mon, 19 Nov 2018 22:53:14 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36108 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404758AbeKTDvp (ORCPT ); Mon, 19 Nov 2018 22:51:45 -0500 Received: by mail-wr1-f67.google.com with SMTP id t3so2750105wrr.3 for ; Mon, 19 Nov 2018 09:27:20 -0800 (PST) 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=f7KSm+jFXQkCQXEc5rnrCA4r7eJPDm1tJhN4hvjkMsI=; b=pxIEoLBVS/155thk/jlirYN+v21XOcVr2GW9d9IBt1OVBarBjRyqIHbmLLhe8psyyq 5Ug5UTJ5X7VrMdCeKBD9K2dkVd+nc0AzF32lJLmucUFRU/GgpdqaUcMhykaBbosPF6dk KIu1FcKLwylt2oS/TycDYqUiERABjULH2Gwy1yv1Mw7ZhgGAthWgeAmCkVzYSlPWpzD8 5Aa+fhgB4AEe7eG4R0/QPBHYc+/htnw7UG7ePdKyWf6uffMpCJytw1h3Wnkeg1RRvRGs 9OTHbUPdKOxvcS/eCi6mPSgOtTdigpIKY3SU9AHkvrAMtJbrq82+to13FudtfZ995L4C EmVw== 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=f7KSm+jFXQkCQXEc5rnrCA4r7eJPDm1tJhN4hvjkMsI=; b=AaZscb8W5KRv3SghzTmmCYyNmujrvFttIdmiay/rp0Yi3szlILazKlWmAkOhDcQYdm Chc/oUWQN00pgJEVSO4tkHejvYfRyD8xGG+efakPMfjzCLUe8FLynIppwvFY7KeGOytz H9tP3gmt6T8Bb5igbw1CAVm2Twd39RiZtPydMsZEjKQgSjA/BKjBtzsH9Q6nvqmm8dO9 1T9AXYC41sse+L8X4g/1EGPXTfpqzwRj6XwXW0OdQ1TG53l+HyCO68sO5Db80beVoS1y /JnY/a3v1bsqx7U8BIlbwf8d/6KhoUOJuwdd1tF5VGfmOaAgrLJ+FStw7h6DexZlIUY/ YSJw== X-Gm-Message-State: AA+aEWZ04mDJ49a9Bnxj9YExyGi/toVlCiGOCHwSb4ZG9omz7yijN93Z MqNur4gCKu9vPyxKFHIqpaVWzw== X-Google-Smtp-Source: AFSGD/XZpgLAg7rezu/mjkHy6lW0RJIb0uV/wXKhtOG3pV2Pb/tXon7urXALPBJFf4VkMPoh4EQ6nA== X-Received: by 2002:a5d:63c3:: with SMTP id c3mr2727742wrw.215.1542648439441; Mon, 19 Nov 2018 09:27:19 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:3180:41f8:3010:ff61]) by smtp.gmail.com with ESMTPSA id l143-v6sm23685190wmb.23.2018.11.19.09.27.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 09:27:18 -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 v11 15/24] kasan, mm: perform untagged pointers comparison in krealloc Date: Mon, 19 Nov 2018 18:26:31 +0100 Message-Id: X-Mailer: git-send-email 2.19.1.1215.g8438c0b245-goog In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.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. 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;