From patchwork Thu Jan 3 18:45:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10747709 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 35A7714E5 for ; Thu, 3 Jan 2019 18:45:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27CE328D06 for ; Thu, 3 Jan 2019 18:45:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B15A28D12; Thu, 3 Jan 2019 18:45:31 +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=unavailable 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 BA58428D09 for ; Thu, 3 Jan 2019 18:45:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A0AD8E0096; Thu, 3 Jan 2019 13:45:29 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6D7C48E0002; Thu, 3 Jan 2019 13:45:29 -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 55CAA8E0096; Thu, 3 Jan 2019 13:45:29 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by kanga.kvack.org (Postfix) with ESMTP id ED80A8E0002 for ; Thu, 3 Jan 2019 13:45:28 -0500 (EST) Received: by mail-wr1-f72.google.com with SMTP id x3so15825536wru.22 for ; Thu, 03 Jan 2019 10:45:28 -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=LcZuxDuPGnY34gBBOzPjzW9RC6MdmGqedzN7uzgRX8A=; b=byYlg1EpgjiucF7p/SOvyvie6QjY2Hz1oWy+l8MJRbHrrIIcFln+RMQu/BWI3ORscQ aoIOOeLAjYaeNhQB4Si2tRwPxxh24vfi/HJMk+CnyU72RB9kKoZDBxtnT80WXGvfGfgi tJ5fCRvbw+fFKiObCVwazVBGDXFXN5njqo83cLA8zjZewAIoHL+eWaU0Mfcol9Pm2PoB 1dmYQL4+LBS4TuyH3P2gvFd6gZP3GPSQ13rNVxM3X8vH1DDvRVeD1Mj9HwAm47VPY4lM Ujwk7Yh/pHi7yllt8SpjSp9CnqB2r3JWn0l7W8B7XqBbfeH/5qPKQoCXogNexJBgKBnn 6KLQ== X-Gm-Message-State: AJcUukfbGOwhQsfh8ziV+kKNMiDU03sl4PSnzrpLOi9xaFZJSbzq299u mGzIJIUNkbbhl6UH/cMl+7jHZ7Bz4cvZxgpfpweXevZeRCbew3NNThq0/9L2dtR4K/hxHa1duOe 45tHsiZWNCivx9l/JHpGJq1JHp52BXizGz/4HDaYqm02QOLlOJ4VImeLGROO1ESMXR9d2TaN8zq wrhPGHskgYE9Sii7fG+Im+OhsU14WoWng1yVp7Y8P0UowGz0bT8qPxPaVrx0yZ2/6XcnOeikp6z GOrz7TH93Y0mFuFHh3Hxm7L5KTYPfBHgxMfpdzxoPNxjZ/kDVjTe8y6PtC3H9Y3lriiScugSXpn iFzI+HD0SWJjuEkiuzGZRr+jgBtesOoZiZFF9JoGZXTYdY0o1mW6fTc8/A82BkKA6koe1Ef/wee 3 X-Received: by 2002:adf:e54a:: with SMTP id z10mr40458770wrm.238.1546541128457; Thu, 03 Jan 2019 10:45:28 -0800 (PST) X-Received: by 2002:adf:e54a:: with SMTP id z10mr40458730wrm.238.1546541127420; Thu, 03 Jan 2019 10:45:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546541127; cv=none; d=google.com; s=arc-20160816; b=Xo15607adK8FeJTnYsnEIPseyBUdbxCNxQxPyzotGb1mdIOO7BHdRrDutbDdYOLuUd nlcEo8w/L4a9fqcCv326zFMCGCqS9t9nL9DWm6h3CSQ8IOqsINQurskGEjo7jAoNLH01 Kf1RoM2mWQoyIXQ01jpvx29p+5ISayJlGTvFA4GiZnDnKA93V+WS+BKDVxrcgqYukOnk sOXgn0Q0YFued7KbO6dXNNHtYqV+4H4egfLPomMTyqZdac9CzGvos7P9scM3reuS6RVU OmLnLHYkvsMwX6BvEIpAnAQ2t2/Y1zVUAb82xJmYEOKALTaC6lzn4ZnX/By10J0WMsxf gOjg== 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=LcZuxDuPGnY34gBBOzPjzW9RC6MdmGqedzN7uzgRX8A=; b=nLjEEJ+dS3YgWB5b9iSDF9QRzffmXT9bDd8ZElqtsisEud3uJl2tLCm+f1gvWtuCuT oHEv1AP1wJpXi6bzIc4aFLd5HL4hYnrkivwjOit96NBm2dlKk5TbVRAb1sPiY7yNpl/9 Z7nkrjaDc9AhzzyQeQEy3xJg2ChqCrxHVsnkKB0ENUy1SKZuK0WDqQRDp0BXZTTZ8+mI AY3g2nVfaW3uu+4vZRR1tHCLdOWqz3dEBGECQxt1uUNftvq0uyfQ98sxUBxvZpDXQpou dD9YGAl+JE7muzU/PUjGf6rIN+XvQlXyGALRXA27t0Y9kwm3PD9bbpkssRtnB40HJ9Jt bkHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JzRV4OzU; 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 i4sor28976946wrx.38.2019.01.03.10.45.27 for (Google Transport Security); Thu, 03 Jan 2019 10:45:27 -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=JzRV4OzU; 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=LcZuxDuPGnY34gBBOzPjzW9RC6MdmGqedzN7uzgRX8A=; b=JzRV4OzU47GC2npsOEq89Allc1qgPv+Y5jsoLkXuyflZ9xTmZcqNEWdvopVB2mLN9u 8dO+4sD19DkkXcPnobH6i4C8sPCDcTKX0Zb5bMIzj7AAWZze9z4tJvCau1rxfVHhRRRb jSjusOJhz6SUeB4bWg1pRK3Ec1iK+PCIbicMVihCOHNB3eu8wG57R5YW7mn3YHEbjXfG GoNIzVch9Hl/MBebbU2cyVjj/+ZtkiaLrajzmanxTB4cyMH9xs/7d39MOEsVTcaLg585 xYTZJkUhlbbMrBQ3Hrw6gURwz+PJUt3SD5vFdNZwyzVNZuM8xmb9QtROaHCZOT2IPHuL VF0w== X-Google-Smtp-Source: ALg8bN5f1SEsd4ITLAOkW46zsAXPnkQ0Kw16Q2Kzdp8Q2K31EY+gUdUwN0+RWy+mZNfdm32Jcr+xpQ== X-Received: by 2002:adf:fa05:: with SMTP id m5mr29524927wrr.155.1546541126907; Thu, 03 Jan 2019 10:45:26 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:13:8ce:d7fa:9f4c:492]) by smtp.gmail.com with ESMTPSA id t12sm52236944wrr.65.2019.01.03.10.45.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Jan 2019 10:45:25 -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 , Vincenzo Frascino , 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 v3 1/3] kasan, arm64: use ARCH_SLAB_MINALIGN instead of manual aligning Date: Thu, 3 Jan 2019 19:45:19 +0100 Message-Id: <52ddd881916bcc153a9924c154daacde78522227.1546540962.git.andreyknvl@google.com> X-Mailer: git-send-email 2.20.1.415.g653613c723-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 Instead of changing cache->align to be aligned to KASAN_SHADOW_SCALE_SIZE in kasan_cache_create() we can reuse the ARCH_SLAB_MINALIGN macro. Suggested-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/cache.h | 6 ++++++ mm/kasan/common.c | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/cache.h b/arch/arm64/include/asm/cache.h index 13dd42c3ad4e..eb43e09c1980 100644 --- a/arch/arm64/include/asm/cache.h +++ b/arch/arm64/include/asm/cache.h @@ -58,6 +58,12 @@ */ #define ARCH_DMA_MINALIGN (128) +#ifdef CONFIG_KASAN_SW_TAGS +#define ARCH_SLAB_MINALIGN (1ULL << KASAN_SHADOW_SCALE_SHIFT) +#else +#define ARCH_SLAB_MINALIGN __alignof__(unsigned long long) +#endif + #ifndef __ASSEMBLY__ #include diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 03d5d1374ca7..44390392d4c9 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -298,8 +298,6 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, return; } - cache->align = round_up(cache->align, KASAN_SHADOW_SCALE_SIZE); - *flags |= SLAB_KASAN; } From patchwork Thu Jan 3 18:45:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10747711 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 9A4146C5 for ; Thu, 3 Jan 2019 18:45:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8ED9A28D06 for ; Thu, 3 Jan 2019 18:45:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81EC828D12; Thu, 3 Jan 2019 18:45:33 +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 294F028D06 for ; Thu, 3 Jan 2019 18:45:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CBFD8E0097; Thu, 3 Jan 2019 13:45:31 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 37D628E0002; Thu, 3 Jan 2019 13:45:31 -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 1F5688E0097; Thu, 3 Jan 2019 13:45:31 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by kanga.kvack.org (Postfix) with ESMTP id B785D8E0002 for ; Thu, 3 Jan 2019 13:45:30 -0500 (EST) Received: by mail-wr1-f72.google.com with SMTP id 49so16328397wra.14 for ; Thu, 03 Jan 2019 10:45:30 -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=wqfuZcAjUCBtOLKWkS6SRZq/hte3EYpV7rEPQw3hkz8=; b=UAXmDlYeUCZWTfcJp+sqKDMbBD6Fx6CkmIenp06jmNtmLm20JlEMdgepWp43jYY484 lhkXmAwxA5r081vpJD0KaSaNTiNjD7nhNGEvdXAprgSxT593ADibXguVYGi4Q585l4US X6zfOkKWn+YYPnK3mHiZKEWWbD3DHJdFN0OS8MIXjk7zGQOgTbEvU6XbmTIP34dNaFFv EAu+Wr5QweJRH4010jBa8LoNplzvEvjo+ps19bdS5PwAGkpRAw6P0yC5xbvHHA8kAh2W PO95R4Ndu12BedTysGN9vQzjhciFw++PXEla+r1+VUWY+otDzoE65Z4Pt2oWW1lT4mwl hbhw== X-Gm-Message-State: AJcUukeTZF1gSLzgueZMWquRfOUAYetTYPN+3FcE+bJw+mtLFRhoaEU5 aIbT6nnx1K6vvfuhPP5ANoavoNRTk9jU2YLtlbgk0y+xrt+dJH/aJqXi5zsQjaviXtdeTw6rtBZ 5Uk1oJRpUux3Ngx4Cr9B0QeHLf77n9WrJ7dKJx2rijQ37OpP8wXhNHDnTepMx3uejNoYdi5+gxk G5SrL0gW/lSpKQ3thptOlwhnrfniFyl1T2GcAukPUoekcIrdEOyHjFqISIpaEypvMjcJCeSpAMb ErM+8BdVMwBcYPXBBdj7qUQIDxW2ds6Wb/KZjYPo2jYa37vifB+zIuFtKgwIeEkOXISJ0TiGA8A rf3B7elkcmyTKAPTzTfTyldrxUIoJ50uVPS0BeDSJqOllQHDRazwpig8CMMA+DGzoJWSUj3tAG/ o X-Received: by 2002:a1c:1593:: with SMTP id 141mr38330825wmv.85.1546541130266; Thu, 03 Jan 2019 10:45:30 -0800 (PST) X-Received: by 2002:a1c:1593:: with SMTP id 141mr38330791wmv.85.1546541129422; Thu, 03 Jan 2019 10:45:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546541129; cv=none; d=google.com; s=arc-20160816; b=txii0hPgYlZshGfpZ4yesLJXs7x7D+VTQIFJQaOy0oIiZKSdDyAmtGPLwT8oggoKml zyp1fdHp5OHGoEMFDBJpH1bDeakq/Bigc4rejjy+SHewuSMIlLzHwz1KsmNEt9J2zRCy VK/5X1DIxOZO+wu3z392Q0x9q4JHaPTkkbM/FG4XqetkyU2tVLd30VOOmVDLMUB6c00/ gZNGp77OrPGy5GaTMwkdqCJpfnRZvNhNce7QxrIdiASTvJdOtqIQ5IBlSPs4mjuNSUk/ f1DlDnodBsQIqoyWTbz0wGBc53TkgXZcFhJuqv1hLVgIkgJPOuQzawayRw78uMKZ2OEh t9CA== 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=wqfuZcAjUCBtOLKWkS6SRZq/hte3EYpV7rEPQw3hkz8=; b=KUiA9bo/ymQqkLYlgkO+SWMu0Y77MVm+iyM4LBb1pRZZama+hNTYNOZfPt69nA37aq lcrXHauz/UOOICJfXa+Z7IUnstYh84w2gVtdLAvOSpLUE7p2AHtZK8WHmyPY/bExy1k4 +J53pBFI5mRVH6gnj9P2qQ9fhOc1HuJTkYRj4Dsf4IIAZPhnw7P3KvQ2aYgJto/MRcw9 Q/CZ90OpEwu44v6UK5teg7N0x6CDRhARpNtDyfFp5uxqT5Ykn8xUcJ+8JIU76hIBu246 6FaCx0oGwWItfEKxDYHG3j6yAb/31023AYY6/EntUv5bEmS+OwyR0++VL2CxO9+ULKEj DH9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ba8p1LN6; 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 k3sor28929112wre.42.2019.01.03.10.45.29 for (Google Transport Security); Thu, 03 Jan 2019 10:45:29 -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=Ba8p1LN6; 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=wqfuZcAjUCBtOLKWkS6SRZq/hte3EYpV7rEPQw3hkz8=; b=Ba8p1LN6oK3Pi0Fl7zZMXYDUR1uRcqSUKMdpT1Q7mAQ6syoy5qLvkHGMUj6j/vGuB2 mPO5FuGEoA96YcXVqzSpSwHEKELmv7R+EvR+inn+PIduuMt4TwXWHgaGeZc0ky7vvm86 yH9L4u9oYTTxmMJbx5HQX1aqZm017enJlCtGAbNGdHs15wOBu7Y61tXbAM6zeVySF49T mmuEIvLHrEZb5taS7g9ooF90sN5EBjH7gGfduXn1VTHmhUOpSR2P22jZqk1x1eBZqFiP sH2YY6VeZEfqquy8gfHxRd99KsANe2ythZVkjVH7ZxaZekAiskkZhF+Vg3IKqAONrIV4 HEZg== X-Google-Smtp-Source: ALg8bN4LFcO01Vv4WTRKcuv5YTd1wsOefh/eH/jXvbvXe+jy9rGwknH3ImOWsoQ1UvdKBEe2ffL9iQ== X-Received: by 2002:a05:6000:f:: with SMTP id h15mr40972842wrx.248.1546541128878; Thu, 03 Jan 2019 10:45:28 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:13:8ce:d7fa:9f4c:492]) by smtp.gmail.com with ESMTPSA id t12sm52236944wrr.65.2019.01.03.10.45.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Jan 2019 10:45:27 -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 , Vincenzo Frascino , 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 v3 2/3] kasan: make tag based mode work with CONFIG_HARDENED_USERCOPY Date: Thu, 3 Jan 2019 19:45:20 +0100 Message-Id: <7e756a298d514c4482f52aea6151db34818d395d.1546540962.git.andreyknvl@google.com> X-Mailer: git-send-email 2.20.1.415.g653613c723-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 With CONFIG_HARDENED_USERCOPY enabled __check_heap_object() compares and then subtracts a potentially tagged pointer with a non-tagged address of the page that this pointer belongs to, which leads to unexpected behavior. Untag the pointer in __check_heap_object() before doing any of these operations. Signed-off-by: Andrey Konovalov --- mm/slub.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 36c0befeebd8..1e3d0ec4e200 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3846,6 +3846,8 @@ void __check_heap_object(const void *ptr, unsigned long n, struct page *page, unsigned int offset; size_t object_size; + ptr = kasan_reset_tag(ptr); + /* Find object and usable object size. */ s = page->slab_cache; From patchwork Thu Jan 3 18:45:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10747713 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 1B4A16C5 for ; Thu, 3 Jan 2019 18:45:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B7B128D04 for ; Thu, 3 Jan 2019 18:45:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F343528D12; Thu, 3 Jan 2019 18:45:35 +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 4EEC428D04 for ; Thu, 3 Jan 2019 18:45:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C64B8E0098; Thu, 3 Jan 2019 13:45:33 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 57DC28E0002; Thu, 3 Jan 2019 13:45:33 -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 2BDF48E0098; Thu, 3 Jan 2019 13:45:33 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id B5B888E0002 for ; Thu, 3 Jan 2019 13:45:32 -0500 (EST) Received: by mail-wr1-f69.google.com with SMTP id v16so15824101wru.8 for ; Thu, 03 Jan 2019 10:45:32 -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=loqk+YaJssCyhGzAFNinnRGb50LrNU13L8MGywEfc18=; b=fHWUlJ1JS341LFxIOvS37OwsXeV6FMoMYNKqql+AmrOiVD+R8CDPXN/2F6KOXCKaWf vbDYwlO4mYGC3oHaJ2wHAtC/euhpRYCdKuoz9aEzk37v//8ikeb2T38Aug1uSVbEgYhH zVwibeCxmUI8oao769qcWjV+JWCkjoGvfxQH61g7gqfyDHGc4HwzPEcEQCbPhOfjX5wK Er/mSJ1WF2laICDeud7gITHQSD8V9ZGvwyi+nRoRD10yuYfMrLghpycRCZgwHG8Y7FtG k8gG12Iv4J9aTBfeHFjfRR58A40b4/Y/aQ71WO26vUTgDBII9ktl0AqNZlhefYnKMXuG l0ZQ== X-Gm-Message-State: AJcUukd6vB0AAlgAaguoCyU+/ulXyXInNBlnD9oqY5699pPZwmySzKPe +z0i9sqST0xeT65wbJ6TXVN2ehZ2/PErWVABI2K5vWVOYsyUvz+M8WSGBuBEqbBZ0TllIiPLvO8 RgRJcJMft0ZRZTGAYeCwhn2Ms5k6cupg0rCutAgI2R0y2M3NPeznT2TcpajinxN41s/5SRnKZZ9 hlybtTY3xRP+l/oYQi/wjX8i1JRCF630QErzO5j68TLdpyPlBoZpr0SJVQRZwBaKVp0vqGXmEpg P7cMU9FqSZ+agFIgjgQDU3hzrlzTXQdMc4Dou21gEYPMrR+wL4oFbsQmrHZIe8hRQURfBtcPS1A YFv6EFMWbhF6aDtubNvWvr1YAITardu+GYuBBtgD4HF+Yj1TlAzxCAiJAOAdHLH7m0A+ImGZ0Ea F X-Received: by 2002:a5d:6152:: with SMTP id y18mr44760482wrt.141.1546541132188; Thu, 03 Jan 2019 10:45:32 -0800 (PST) X-Received: by 2002:a5d:6152:: with SMTP id y18mr44760429wrt.141.1546541131045; Thu, 03 Jan 2019 10:45:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546541131; cv=none; d=google.com; s=arc-20160816; b=kzcEguo+oqDBvLDCm11FP6R21nzml5MieM7M7e90r3o0NaDOiPChN1eOycusnEKf5e pTB4grDlZqETTMFSbAsv5x/Ac4Q1lZDUG+nNTDrjhB81Je0VANQ4Io17i3uxG3iT5la1 JIm/LGUCKliI+NFPgEdsrthW3b5KtJzaqIEy9wO53gcYMKscV6iGzBZ5Aqphs3qMogy3 EnaOqm5eBWsee1yOQD2Okn4l+HKKdnCENb340K2i0lTH21RZtn7hA8X+EcBfVQSQ1QhS KXe85zsW7Vy7T2CdYfY9LmdloALofgeCPTj3jxzwh7jSUd8kWWdoLb3iWpbU0RqDWeWA pNNg== 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=loqk+YaJssCyhGzAFNinnRGb50LrNU13L8MGywEfc18=; b=PtkQwSSfbePmI/iOyhTDp3SFS3MaB1sJ0a4zuvHf0cMN5Fy+gKkVDj0fTwVkKp7qXx oF3VLS9MchYPA7w4KFzVCBS6gZdlUQluuJfY5zsJwlbFe7C2Q/2otBC1wchotRn4c2LC RoNb/ghnv1/xcIeTCQYTH8BP/NHWqKYuN5yhaB10Ff8m3d690cMBB7Y0ngCM8ne62P2Y foJcL5J9/+GO8hoEbYKrB+keU8EPSbQqKO8aq14e/TPXtiLtxq2Km7UDLXJqnzbzKYI4 v1GS9k7X95CN62A/xtWs2IokTggWmM88cY3fIq6s8i/Sqn6Bi9cYjX7+tjf/kpq2Hth8 CrcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hTmg+DGu; 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 e5sor29261177wru.29.2019.01.03.10.45.30 for (Google Transport Security); Thu, 03 Jan 2019 10:45:31 -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=hTmg+DGu; 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=loqk+YaJssCyhGzAFNinnRGb50LrNU13L8MGywEfc18=; b=hTmg+DGuRIQF2vlqz/Vhl1D+/+mvgPMsjqLDHi0P1rk+WOre7zmTu5qqGxv3MuZCCE UmLGhAKFZbzdsd4JMY8pdmgI4HYcHr4YnHntxG+Gt//m4C9Qndntnz8PKfjmfZeLTDpd K0fspUq1NKHV5A284NV0qPwtJ8DdvroBOj8kdD2qczrMK2lmGiPk5KVZxusGtbJdfqwR UUZxn2Qs6thHtP1o2ZG8BwsnsoATqNMckkznlYwnbdZQ8C3QDsxrTRM76uXF0vMqJHwb NV6DgqPzaJ4SZY9nrBP+8lLvzwTIs4vFYaq5Eyd/Nw+pUV8pY0KTWdZ5qFjegRMm8Ha4 w6xQ== X-Google-Smtp-Source: ALg8bN4jM3MVHQyzwSzizLWeommEZcTAUOfqxGGPUDgiXkfn7dghhnI866UT0Yj3Z9dcwdbzSDIU7w== X-Received: by 2002:adf:e34b:: with SMTP id n11mr39771740wrj.91.1546541130566; Thu, 03 Jan 2019 10:45:30 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:13:8ce:d7fa:9f4c:492]) by smtp.gmail.com with ESMTPSA id t12sm52236944wrr.65.2019.01.03.10.45.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Jan 2019 10:45:29 -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 , Vincenzo Frascino , 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 v3 3/3] kasan: fix krealloc handling for tag-based mode Date: Thu, 3 Jan 2019 19:45:21 +0100 Message-Id: X-Mailer: git-send-email 2.20.1.415.g653613c723-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 Right now tag-based KASAN can retag the memory that is reallocated via krealloc and return a differently tagged pointer even if the same slab object gets used and no reallocated technically happens. There are a few issues with this approach. One is that krealloc callers can't rely on comparing the return value with the passed argument to check whether reallocation happened. Another is that if a caller knows that no reallocation happened, that it can access object memory through the old pointer, which leads to false positives. Look at nf_ct_ext_add() to see an example. Fix this by keeping the same tag if the memory don't actually gets reallocated during krealloc. Signed-off-by: Andrey Konovalov --- mm/kasan/common.c | 63 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 44390392d4c9..73c9cbfdedf4 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -347,28 +347,43 @@ void kasan_poison_object_data(struct kmem_cache *cache, void *object) } /* - * Since it's desirable to only call object contructors once during slab - * allocation, we preassign tags to all such objects. Also preassign tags for - * SLAB_TYPESAFE_BY_RCU slabs to avoid use-after-free reports. - * For SLAB allocator we can't preassign tags randomly since the freelist is - * stored as an array of indexes instead of a linked list. Assign tags based - * on objects indexes, so that objects that are next to each other get - * different tags. - * After a tag is assigned, the object always gets allocated with the same tag. - * The reason is that we can't change tags for objects with constructors on - * reallocation (even for non-SLAB_TYPESAFE_BY_RCU), because the constructor - * code can save the pointer to the object somewhere (e.g. in the object - * itself). Then if we retag it, the old saved pointer will become invalid. + * This function assigns a tag to an object considering the following: + * 1. A cache might have a constructor, which might save a pointer to a slab + * object somewhere (e.g. in the object itself). We preassign a tag for + * each object in caches with constructors during slab creation and reuse + * the same tag each time a particular object is allocated. + * 2. A cache might be SLAB_TYPESAFE_BY_RCU, which means objects can be + * accessed after being freed. We preassign tags for objects in these + * caches as well. + * 3. For SLAB allocator we can't preassign tags randomly since the freelist + * is stored as an array of indexes instead of a linked list. Assign tags + * based on objects indexes, so that objects that are next to each other + * get different tags. */ -static u8 assign_tag(struct kmem_cache *cache, const void *object, bool new) +static u8 assign_tag(struct kmem_cache *cache, const void *object, + bool init, bool krealloc) { + /* Reuse the same tag for krealloc'ed objects. */ + if (krealloc) + return get_tag(object); + + /* + * If the cache neither has a constructor nor has SLAB_TYPESAFE_BY_RCU + * set, assign a tag when the object is being allocated (init == false). + */ if (!cache->ctor && !(cache->flags & SLAB_TYPESAFE_BY_RCU)) - return new ? KASAN_TAG_KERNEL : random_tag(); + return init ? KASAN_TAG_KERNEL : random_tag(); + /* For caches that either have a constructor or SLAB_TYPESAFE_BY_RCU: */ #ifdef CONFIG_SLAB + /* For SLAB assign tags based on the object index in the freelist. */ return (u8)obj_to_index(cache, virt_to_page(object), (void *)object); #else - return new ? random_tag() : get_tag(object); + /* + * For SLUB assign a random tag during slab creation, otherwise reuse + * the already assigned tag. + */ + return init ? random_tag() : get_tag(object); #endif } @@ -384,7 +399,8 @@ void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, __memset(alloc_info, 0, sizeof(*alloc_info)); if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) - object = set_tag(object, assign_tag(cache, object, true)); + object = set_tag(object, + assign_tag(cache, object, true, false)); return (void *)object; } @@ -450,8 +466,8 @@ bool kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) return __kasan_slab_free(cache, object, ip, true); } -void * __must_check kasan_kmalloc(struct kmem_cache *cache, const void *object, - size_t size, gfp_t flags) +static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, + size_t size, gfp_t flags, bool krealloc) { unsigned long redzone_start; unsigned long redzone_end; @@ -469,7 +485,7 @@ void * __must_check kasan_kmalloc(struct kmem_cache *cache, const void *object, KASAN_SHADOW_SCALE_SIZE); if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) - tag = assign_tag(cache, object, false); + tag = assign_tag(cache, object, false, krealloc); /* Tag is ignored in set_tag without CONFIG_KASAN_SW_TAGS */ kasan_unpoison_shadow(set_tag(object, tag), size); @@ -481,6 +497,12 @@ void * __must_check kasan_kmalloc(struct kmem_cache *cache, const void *object, return set_tag(object, tag); } + +void * __must_check kasan_kmalloc(struct kmem_cache *cache, const void *object, + size_t size, gfp_t flags) +{ + return __kasan_kmalloc(cache, object, size, flags, false); +} EXPORT_SYMBOL(kasan_kmalloc); void * __must_check kasan_kmalloc_large(const void *ptr, size_t size, @@ -520,7 +542,8 @@ void * __must_check kasan_krealloc(const void *object, size_t size, gfp_t flags) if (unlikely(!PageSlab(page))) return kasan_kmalloc_large(object, size, flags); else - return kasan_kmalloc(page->slab_cache, object, size, flags); + return __kasan_kmalloc(page->slab_cache, object, size, + flags, true); } void kasan_poison_kfree(void *ptr, unsigned long ip)