From patchwork Tue Jun 26 13:15:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10489043 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 A7DD360386 for ; Tue, 26 Jun 2018 13:22:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97EDC2893E for ; Tue, 26 Jun 2018 13:22:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C0C42894C; Tue, 26 Jun 2018 13:22:57 +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 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 37EF72893E for ; Tue, 26 Jun 2018 13:22:57 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=66mQzoR1+OtIWQbwdyBdvoahRxrwDQnQ3I9KCwBKAfg=; b=FzB8MLM8kM/ABBHipIzkeBwaDy RIX2kyyd826rnfOBlouGJ6Zdnl7MG1ReyP5jmRmtzL79vZcWsNgRgqMR9OaRpGVsT+XzXe+lcDS3Z 5fIgbbqp8xpkTw7yh5e23jl0O3ayfyZqWJkTepr4+tRcSALBe6mu+c8X4P7jxLw5SvW/JbKt1u4Y6 QNbOVqT/aS5OufnVdsO6Dxf96HOOULDye+vlTImLazTiXIvGvxZ0mM55E66mtnr6/uMzHp6KYg4NX LG/gHF54FH/Lj+H6EbtkEKtbzkVO5XLJfPx1kNoPbMYjvoI2X5jKKjeyif/5GvAyimogUBLKzHE// 2ZQLJm3A==; 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 1fXnve-0003Ym-KT; Tue, 26 Jun 2018 13:22:42 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fXnpD-0007Er-Qr for linux-arm-kernel@lists.infradead.org; Tue, 26 Jun 2018 13:16:29 +0000 Received: by mail-wm0-x243.google.com with SMTP id v16-v6so1897296wmv.5 for ; Tue, 26 Jun 2018 06:15:53 -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; bh=yBPRwBaWYUVSArjumBa6fauS/4DSRyKow4zS0UL3/uQ=; b=F5BA1fb9nMc2llPcpCY45+Govd2NK97f8DeANvLf6/pO+8ZmySSwPGT1QB8mjbGwcm +jBy/JwaDlvGaXBjCxqHRVmaDgiCAUY96hiv/hM8YaY32atVyychrCmE+3/BVRMOsNwp Kn6aKoO5sB6cWxGvwtuGwgOI2aVvPPfsY2sj0pFhyoLksQSZPx/tBv8y5N6P6ypfZ1YE SV/LxGr4VV24bnWuBuEtAb4tit0Eq2C6vck2Um3KnGgDCw+f7W46c4Ntra9VSYDZR6Zh tdwZkPQDXYh/YEwXFnAlSQdYMSz6tay2i7Pj/cLpfnfV29yEN7Nd+naOl15nnSAyJlP9 Iy3A== 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; bh=yBPRwBaWYUVSArjumBa6fauS/4DSRyKow4zS0UL3/uQ=; b=KxH4Lns7Soxo5Xkoom09q5NIZ2Q/d7JLCRwjiqZhL7ouIlp5ojwOQQo7jizGEX7YBr +T5ETVzK+kr51NClOqGNPfCcbkuskpjT2RdpfkYBmU/YW6B2Usi5xsHA+RGUdir7eKMp 3cZt8N0UwyjRp6SZsQtD3+s0lhA7W0sKKiulUkHedjeGnfH86hRYOo1DECNN2gyjJ0Gr m/aK9MIgfCXl0Ow43lZcVjujUIUhQ2VbdTBKky/pSPqvh7yU5+sQgB/VjizvSX5BWlvO 7GVQyOS7Ff++MVysQKAjcFCmZYioyEoyPhkSW1eYKN48IXkxhfL1quwKpiwbO8+zBqFg 4aLw== X-Gm-Message-State: APt69E0E8RXkkSGRe4AZU3wySnfPYh6lRVGtaEW1wgF792x1sEA5k4gO 2N+WWBinITxaHGZYZHR9yEsIRw== X-Google-Smtp-Source: AAOMgpcIZGN8/Izw0CfyPMZx5yvgYHVOM/4GCivZrU5323uijnvw+HedN5vD/6BGwQOLFt2SEUXnAg== X-Received: by 2002:a1c:3504:: with SMTP id c4-v6mr1531279wma.59.1530018952054; Tue, 26 Jun 2018 06:15:52 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id w15-v6sm2162639wrn.25.2018.06.26.06.15.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 06:15:51 -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 v4 10/17] khwasan, mm: perform untagged pointers comparison in krealloc Date: Tue, 26 Jun 2018 15:15:20 +0200 Message-Id: X-Mailer: git-send-email 2.18.0.rc2.346.g013aa6912e-goog In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180626_061604_041919_3B54CE5C X-CRM114-Status: GOOD ( 14.43 ) 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: Chintan Pandya , Jacob Bramley , Jann Horn , Ruben Ayrapetyan , Andrey Konovalov , Lee Smith , Kostya Serebryany , Mark Brand , Ramana Radhakrishnan , Evgeniy Stepanov MIME-Version: 1.0 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 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;