Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp5157989imm; Tue, 26 Jun 2018 06:53:50 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJBQVDLkJ6Mxduc8o+7tzwy+kje3khBxvp1Qb6yEI+MlMQvxIduZIOKZxSYBgGUhRFwsINR X-Received: by 2002:a63:b256:: with SMTP id t22-v6mr1512903pgo.101.1530021230359; Tue, 26 Jun 2018 06:53:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530021230; cv=none; d=google.com; s=arc-20160816; b=J2Rl0nNUPtXmFI5H52e+rnrmsAqFqVZ8sAJNz0fKdyzSqNl2UbmyabAgJbnkYGLO/k LDDE+7Vj9mjOtCZ2nHPD4wQfoB/DkwvJLD1O+ht3VhqSmAOCsGg3SjNwvgaENYkWHb9p i+dOCYSZugPV9usipJvavsmdAhuKWSPFpxso4YmtabXBDAod/HnvxJwNH9x4/GSraIih XIwGKZnApxNnwRaQenXyvaD4G4je/ms2AXgPEIYL7mcSYCwhmzHHLN2fQaYYGsPJOupM rVkYukY1QEjMQf/tX0CUvFO/fEJ1hvVGBhw/SYP/4eS7uZWqiMhYuRb3B2dIQa5wDnk8 3c7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=yBPRwBaWYUVSArjumBa6fauS/4DSRyKow4zS0UL3/uQ=; b=myroyKmsmw41mJ+cNcyECBG9uOrHiZtOiqw7TdiqCaLtfnhVZ0VTyE8q3gJvjjGiyT jQ30v1cOp0P9LzGU3M1biMrJ5VY9SJ0B4Eql08fCguAVP8AqtUNBST/dJlDXWexoFHlP k1FTff04Y6gI9mFyIS/9C0iAF95K1UwtxflBB2SxJiNPZDYF0d9cMNiRatGdNDB/647I G6MeSG+oXhg2btdXBhqPhouGyJBAmbtOwwoDDVmYjzzuZmnVNmYbqRKo3gZh9BqOUTPb eJFLO8v0aC+ZLtK2O3ElWqQNupSdNojiDBk03xxqGQZ5pwECa+zrHSECVMpswlQB7M+T 1jpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=F5BA1fb9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a36-v6si1682541pla.207.2018.06.26.06.53.36; Tue, 26 Jun 2018 06:53:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=F5BA1fb9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965436AbeFZNSd (ORCPT + 99 others); Tue, 26 Jun 2018 09:18:33 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:54331 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935520AbeFZNPx (ORCPT ); Tue, 26 Jun 2018 09:15:53 -0400 Received: by mail-wm0-f65.google.com with SMTP id i139-v6so1881849wmf.4 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=eEojwjNjfE8RNtmruR9MP/pWnsvBwqLtDwIMeu4fZTR9fgASuoqQ5C/Hxl60B2onMI 7EYJnh0I0VXSE6UEV5oMQOy5qQzmVMChuSEHTiq8JIMaexEiM0BXcTrxJQdbUQRKg09Q +2wU1i84Mx/4ddFJfx0cvyDZ8TZxl9XWd6UOmtV43FWR9mtd36umP241X8+zWvGHmdHr 9Yq/Z0IwwIsbNUMtxWBcxiiVQ79MFkSKLi4o5Lmr6S2T1SqbPkB5ZQFRYyP+53FZrEY8 pcJBqrWOLeElcYG6i0Z+ATxfrdeP9+3onvHrOCOe9/fNtT3yAjSx/KcN3cJZtCZB+E7X WZ1Q== X-Gm-Message-State: APt69E1CWnW6OCTyuEcPYTlZNA8O6W7susMZxzcgeCLLiRwXzvXLylFE Cd1dDRHLeGxQqMd9KE/W9dgghA== 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 Cc: Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Jann Horn , Mark Brand , Chintan Pandya , Andrey Konovalov 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: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.18.0.rc2.346.g013aa6912e-goog