From patchwork Wed Jan 2 17:36:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10746551 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 648E41880 for ; Wed, 2 Jan 2019 17:36:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46CBA28405 for ; Wed, 2 Jan 2019 17:36:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 399F928417; Wed, 2 Jan 2019 17:36:19 +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 9F92028409 for ; Wed, 2 Jan 2019 17:36:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B1918E0032; Wed, 2 Jan 2019 12:36:17 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 663E68E0002; Wed, 2 Jan 2019 12:36:17 -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 4700A8E0032; Wed, 2 Jan 2019 12:36:17 -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 C03EC8E0002 for ; Wed, 2 Jan 2019 12:36:16 -0500 (EST) Received: by mail-wr1-f72.google.com with SMTP id 51so14900170wrb.15 for ; Wed, 02 Jan 2019 09:36:16 -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=ZsJFoVJf3IIY1mc4G8PoWo9I+7LoITd3hZ2Vo5zkWAc=; b=QwCUOXZVQPk0Lf6b7D80HxcL2xwm7tC48XWuOgBI/qm8gQjjrtRocN6YFEVs6fADKD SKZ77OoIZiKp2bU463emiUGX1Y76U3Ac6iFii+uW6DBPbxoz5hbzQ83q94FbPIsBjaXe tvFuMz/+Dayy4ZSHu6PpFz6R+4dwutYlHT76SFwcCIRMY2/ksQxrVoflXvBTex4bChcK 42ixisKy4pZ+qLU7pEuptTNCQZstRY8I38JHYaW2e6F+OPQ38NSc/yD2Iysyt1m5PU1u uKyRg9aYUsFs4fzT6BlGMX0jmqGmYNWQBPneaC7sKZRT9HjXnSvHvneWcBK+rS6DLbkF zXOQ== X-Gm-Message-State: AJcUukc40cInKZNPGAjtjaa5OTbhz92kdulJyYWiT8F/pUe6lqrbLf2D y94konsGTN8FNpgfL7UrrI8n6gjBPRY865KtG7GT2Z6cyX8eZbmJnqrnjdtjG8he+2jZBaIfyAn EH2f52QIYTqwpEhXMmaJLtMQHTfCKTgQSkQuFUvuqCwgxXSUECpq0Wi4UK1eMfZbEtz/Vq+6ACU noVPkUjhdmTXB28HmMiyMycrJ7/RalYcUC3R+cdiwB0EJGMi336cQSo5/nWBrL4D+jG3yyMfI+a 7x1kDccC6nKSiE1HqGt6MYTkgzw7NvSuwJ5RwYBRbsz8Kvs6cB/Le+dZmZyd76Gy+PZFkX0nZW8 3rBdRcCx3vVW+m5dH7AiPNWIX/sy3rPMGKiZdIzeuK367GcHnBQPMLigxhNTs0lRZTREZOjCm03 X X-Received: by 2002:a1c:48d:: with SMTP id 135mr35053833wme.1.1546450576301; Wed, 02 Jan 2019 09:36:16 -0800 (PST) X-Received: by 2002:a1c:48d:: with SMTP id 135mr35053813wme.1.1546450575448; Wed, 02 Jan 2019 09:36:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546450575; cv=none; d=google.com; s=arc-20160816; b=x8DsMwOe9ZbYIde0bJL2WCo3X9ZPtvG92HAhxTeWldumSlRk9wOjmsYtlLHZc2nj5J HTMMziDgERuFSR6MFtSC4Y7d2GIE8FpHfJrAzXjt40r5uqXznaYtV4OIM5PRoeE0Lo4W SwdbchvipOkOrguYEEZjQTE+eGYcCPtS5yXjOUktoWsyR+tZPFFyxhMv36S0ebZEyN7n AQi0Nnq2JVkH1HzjxBWkBeZmvIQyIVXY/RkARfOGZ0OwbZaTCbrHcUPN0x1ko87VMvsu ees6z637TuzOaB7B4CVHjFok3xxcodZlB7acwRwIq5wYlWjzmIgKmVEUdb2XNDED28lt 76qw== 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=ZsJFoVJf3IIY1mc4G8PoWo9I+7LoITd3hZ2Vo5zkWAc=; b=g/cbbh1t/C48WtkfQ5qMwdP50oU8G+7PBg1M47wRbpsF+Ym4+ByiJ7K1VqXLBUXiF+ VVYVLIqVbCstLuzxwi/S2YKD483krsB6urLSOm4okLf5vRvTYLBUajnhU0kda6/4ySwZ 2IVuw3CI48gM5+FF9A4plWBdZFoXJbWyaPH7nYZOT+usgzkajoTSxAyC7ahoyfUagKvG GPExCszMHUIigPbBJtPKh7Q5aurMX4+e19LDLMKN9rh88bP6TlIKHHq1uNUi1L1eMdKW 703QvO0TtBpYETpuogKbwjB/SRvKNBWMisP2ksAzwWQ31YTHm2iZZYtOd/xM34A3kEWM q3qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lAlrMqV+; 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 74sor19820083wmm.16.2019.01.02.09.36.15 for (Google Transport Security); Wed, 02 Jan 2019 09:36:15 -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=lAlrMqV+; 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=ZsJFoVJf3IIY1mc4G8PoWo9I+7LoITd3hZ2Vo5zkWAc=; b=lAlrMqV+AGSkWFg5yrz2JZbPk6RoKIqYdaAHGwn+o5V/PT3wER7ZaMKwkE5hdb8SuZ LPObNhnGQkXOjiShOE7KLEe+L83ocrpqNvR5qQwkMP5Jd9WvyCHU1XtGvb8QckxB9cCo gFwgxa8I2Z6nAI/XlNVC2sTC4UcKZCyjZClhL4LmKKz7nwSQmrvkj3eDWI5v8Qyf3dVU KN+qP7/l7ObKbX4pR3rxTA8VymtrWoOGIyD2lKYFGn5sBzxkrkvUhOi4CFKYCGGGVkVv 6IVZkI9DYKZ4d6sI3dIg+OQntY2oMujijkTJspbpA7hPOjSgmSOqiAXGwZvhxQwTzZsC vurA== X-Google-Smtp-Source: AFSGD/VaDhJ7tSu1Glf9joOK/KwNwzfxgXuAYl8ckeRSP/aFiyqPuu4bYT2MGG+9MfJfx5N6OAZhBA== X-Received: by 2002:a1c:7511:: with SMTP id o17mr35511822wmc.42.1546450574842; Wed, 02 Jan 2019 09:36:14 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:13:8ce:d7fa:9f4c:492]) by smtp.gmail.com with ESMTPSA id t4sm45987076wrm.6.2019.01.02.09.36.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Jan 2019 09:36:13 -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 v2 1/3] kasan, arm64: use ARCH_SLAB_MINALIGN instead of manual aligning Date: Wed, 2 Jan 2019 18:36:06 +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 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/kasan.h | 4 ++++ include/linux/slab.h | 1 + mm/kasan/common.c | 2 -- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kasan.h b/arch/arm64/include/asm/kasan.h index b52aacd2c526..ba26150d578d 100644 --- a/arch/arm64/include/asm/kasan.h +++ b/arch/arm64/include/asm/kasan.h @@ -36,6 +36,10 @@ #define KASAN_SHADOW_OFFSET (KASAN_SHADOW_END - (1ULL << \ (64 - KASAN_SHADOW_SCALE_SHIFT))) +#ifdef CONFIG_KASAN_SW_TAGS +#define ARCH_SLAB_MINALIGN (1ULL << KASAN_SHADOW_SCALE_SHIFT) +#endif + void kasan_init(void); void kasan_copy_shadow(pgd_t *pgdir); asmlinkage void kasan_early_init(void); diff --git a/include/linux/slab.h b/include/linux/slab.h index 11b45f7ae405..d87f913ab4e8 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -16,6 +16,7 @@ #include #include #include +#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 Wed Jan 2 17:36:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10746555 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 440496C5 for ; Wed, 2 Jan 2019 17:36:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26D1528405 for ; Wed, 2 Jan 2019 17:36:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A30E28417; Wed, 2 Jan 2019 17:36:21 +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 B51C028405 for ; Wed, 2 Jan 2019 17:36:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 09A128E0033; Wed, 2 Jan 2019 12:36:19 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 04A7D8E0002; Wed, 2 Jan 2019 12:36:19 -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 E2EB48E0033; Wed, 2 Jan 2019 12:36:18 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by kanga.kvack.org (Postfix) with ESMTP id 8801E8E0002 for ; Wed, 2 Jan 2019 12:36:18 -0500 (EST) Received: by mail-wm1-f72.google.com with SMTP id s193so4094491wmd.4 for ; Wed, 02 Jan 2019 09:36:18 -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=dwWP9uMK2yXjYU01ecYSRl0DJAk5vdTy8hrD6OzCydL+XO1BG0exfvrquiB4RBkVQf wnPfP0y5PM0e46r6jFaL3J2es9lTwdpb5iqhHPiIa5Z+GlCSV7nt72H3/GzqNARvJaF/ EzRBw4+FkTbFmvpQw19mgYIwFNxX6Z2xhx1iRMxrRDwMFe2N8rDL5hcb+u4Vx1dATJdN i5Q8ncjeAwDXMBdLvPV/7j8ZSNXJWprTkZJ4st5bBYL+nu07WPwrkEEIVFokTfEyUBuW QZ/mO2w0Uu3zprz2hEuwt/5sGhh9wgnj6hA6bwbm4PpCRnnaycmXAUQ2JB/L5XTqMkiP tJqw== X-Gm-Message-State: AJcUukfD908XTWL3DmYobGyjg7wnQAac1BjNaPRGapTwqUL7kQ52InvO WEIfDDbf2bpfQwLYbOUC0q0Jx18P43/+niTW0BswI9Xvg/kwJTD6MzgzjiT7y+bOshVycjLV2dd 54zM3o+6TAERBsfgs+1Sj3VkuoXnxuUOLpL389G9mvC4BYnbkt/eXiHFY8/OeDbfmNVkhMi0Tfc d04LyBBacT779gZiEgvuoreVztzcpVKYGWm9EqpIqGmbGSI+ONPtofJNUI1MTdKoZ/oiVRnTKzL atCheNt5w34JHo9w084fYydXuwlngq3szbS6q0Zf2B1EoD3QUf9ksIWA6+Q69sZ4iTk2gVfOMe4 nGIt6ld55WCoZetI2CVt6UKbDDqOifXjeOCmaKCgKbipbhGXVX+6CshkWlv0/rxD+t2oz+pOvq1 m X-Received: by 2002:a7b:c7c7:: with SMTP id z7mr38542677wmk.74.1546450577917; Wed, 02 Jan 2019 09:36:17 -0800 (PST) X-Received: by 2002:a7b:c7c7:: with SMTP id z7mr38542654wmk.74.1546450577075; Wed, 02 Jan 2019 09:36:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546450577; cv=none; d=google.com; s=arc-20160816; b=HGgtfPvW2BR4nKmGKz2yfGThJXs6iV+is3VLzBWLfI1L4vN0Yv1gU4hkZuVs5B/qR/ nWz6lUgA8c87QOwCkI/Up1fOxLM7dh4zZkoivkYzQjYmgjE6ILva11vTFRDioIT2rEbv VYWaCCTN1cBUi6/JtWpYJ4akamuCO23bdaf34FgM2rdHXLfJY2HTg9fyx9QZHZrtF5z0 eFhmygwRNDSy/MGbH8HwHxWOFFcb7AhF/H4k/EkTlk3lJFDHPigfMczRlbL0tDKopuQJ wZZH9d9ixw60HjYf4bxnu+/NP3jFTHjDX/uWcmIalFiOu3l76WLpDAYcdv4O58A4w5xx xlcg== 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=MN35AR1qmCEpVRySLSnzqSVx9F/YV1sjib09tooFxRSzvx5fsCcgYJ0/dTFF4r5TZ+ S4agxZtNBebJrXfUJG7MpT7hxr+7lmse7hQy+CZC9QNzy5stutHpqwnVOF0bQq+OQRle DS9PJexlNTnKEhF8UPhxToAgauvym9UNWNscDoOk7jZbrdN1B98zxDFpJyS9cs/tQKjY f/qOZpq3OQ8EujqQ5SRSv68T4uSPm3THqPeuizuvKM7sYQg4Q0cAMFvCe8yy42nH4ZG9 PLZ1vIRGO7YniJe7g6RfKWWZqb+t6J+jdR46mAntmz55Khv0bPq8kdB0rFMM118+UGfQ 4dDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GBABedig; 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 201sor25633308wma.0.2019.01.02.09.36.16 for (Google Transport Security); Wed, 02 Jan 2019 09:36:17 -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=GBABedig; 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=GBABedigx8sH5GFwpRqipEDZ14ymhRvEFULjEU8wLa/LptdTisVFf9skUy8ylEKwgj RF12pUwr344Vyvy3ZqJC4iKm1OZSWqoVLD5mJZkl91WIY/lo6o1i2e7+QvZjCRXC8gqD TalGJ7+keqs9g4ydv5W/68JCwOiEcJUrlW170vCsYKVKJdezXyBqilxWlN06NaZHYTDc QQgWpPrpqe6SqK7zrP/HpOaRELc378Wew1Pp2kpkP+K7TKwG3na64p2Wzdh2fIyKQxWR 416+4i3iHDx7qlDktBw/RgIj4tv1H8OekGka2BVVugetEBDgCsmpkgmw/g7V3gWXuDyc OjoQ== X-Google-Smtp-Source: AFSGD/W97uWDkFBwjy9qVKlmOmTQCuBOdfdQInnihelGax0GIIIDp5gYRmDwwP96Pfhda8t/d8RaVw== X-Received: by 2002:a1c:4108:: with SMTP id o8mr34987293wma.91.1546450576552; Wed, 02 Jan 2019 09:36:16 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:13:8ce:d7fa:9f4c:492]) by smtp.gmail.com with ESMTPSA id t4sm45987076wrm.6.2019.01.02.09.36.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Jan 2019 09:36:15 -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 v2 2/3] kasan: make tag based mode work with CONFIG_HARDENED_USERCOPY Date: Wed, 2 Jan 2019 18:36:07 +0100 Message-Id: <21de3c171438760a232d51cea56792c886bc9160.1546450432.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 Wed Jan 2 17:36:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10746557 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 0F1AE6C5 for ; Wed, 2 Jan 2019 17:36:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4C8C28405 for ; Wed, 2 Jan 2019 17:36:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D40F428417; Wed, 2 Jan 2019 17:36:23 +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 05DFB28405 for ; Wed, 2 Jan 2019 17:36:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26B748E0034; Wed, 2 Jan 2019 12:36:21 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 242C58E0002; Wed, 2 Jan 2019 12:36:21 -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 10CD68E0034; Wed, 2 Jan 2019 12:36:21 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by kanga.kvack.org (Postfix) with ESMTP id 9E09A8E0002 for ; Wed, 2 Jan 2019 12:36:20 -0500 (EST) Received: by mail-wm1-f69.google.com with SMTP id g3so8467093wmf.1 for ; Wed, 02 Jan 2019 09:36:20 -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=JbDh3nO/eQ5r3H90w51/iWL5ZM5B6uICF84/YZhcCg4=; b=RJVaFx+5nj1cHhsjSNlr2BtXffFWfZBKp1VcVoamaDiKw2mIy+KcrF0EmugJqyZtqK cuz58JSzX4Vf2N9V2uUOcduS5uGfJtHa87N38c9v5xfQ18ViTvAVJAT83o/Ez3fRD/ls PV2wG1F0pQEZOuVO7UOULWqFz17ioO0/FIjZ2i0Wx9ydeRta3kQJDi8s6gjS6GbcVd/x lFzsoxRaQAktPpvJr32RkByVVWFpGAoHzEwemYx2U2lXPGDnr8GfXswp9Qhq2pRXmwGY RzzhWCXlT1DVN/laEUsBJW2WkuFFSb4Ln1wC2J1+LVl0PWMuIPabXUX+v44I2FaVtbUr 4bTQ== X-Gm-Message-State: AJcUukcvHjxOVXy7cBkKVwtyeOauPXm/4f7LhDc5kgjKwQsZ79aXGq2r 0FJ9BrsUgsggxV2yFw7n3ScqQ9iMKbPIF/9NJxRKrpOKBY6Hf83IU1qfK/ZY5LlDB65bAaPv9xr QlGzYQ9ZgmLUvZ0LMZL+1lhI530b6ukUtqdnjASuasrG/foyGcxadBPvN3PuU3VGr4jFOvQmq45 GPY9xYEnAo4WMBaslTbOi/EhChlIgOPcoP5vjhKyYkIuIO7a6UnXkUwb+0hs0qhjncjSoT1p5/e ZFGzeD7j7DgfU3BT92QJgkWpcgfy1KNxllOsJc0BpPrJ5usP4449t9VfR1aMaPyAipAVQiOwpQ1 pBJHQEJUiXyKJGFdIulL9jLOUGRGhAvHXXtRWn6p/0bd+xHpyLov/Av8p9i3dfruiuD6y9sSxSR 9 X-Received: by 2002:adf:ee89:: with SMTP id b9mr40360423wro.246.1546450580064; Wed, 02 Jan 2019 09:36:20 -0800 (PST) X-Received: by 2002:adf:ee89:: with SMTP id b9mr40360368wro.246.1546450578992; Wed, 02 Jan 2019 09:36:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546450578; cv=none; d=google.com; s=arc-20160816; b=Fnk72VmWMjEjIKs5Y+FGPLYBY8kFDoFk64eHJpGTuGLHjTEUxuK3jaaG8gyaal0VGF NOIMVyAA4H+Pd0gNNW+Tu29MN+0duAN1lpcBr3xz/tx14kg/vEFTzSsSxTWh1aNyCpVO lxNtTxDDDVius6sL4hy3af7Vsa9pFG9yVhClGaB1RrMEYKI+J5lm+csVETjE99JGtL+3 i21tuzFK04rBVxerJSQEtiiwqQixppnG/sGAdlPeafZlQyMqEsY0Q0SocQ5226M/INr6 JWri0Ui02ZhgEAPqlSG52T9KNG5rX26kAxwqtnFK0VSnjrjVyb+JF6DyxG4rUzDFtQh5 4nQQ== 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=JbDh3nO/eQ5r3H90w51/iWL5ZM5B6uICF84/YZhcCg4=; b=oLTaCMzF8ZpLSEnfu5PPPYSCF3/hoeBJcyrParvYIe8y5TiBQNnMXrIdYVOu2vQ83i vffRbiKGp32iQlvGRIuCd9ojEBpkf7QMlcxyspJABuw56VSPBwrGPEwSUZ7ow6RDFJ5U g4wK+Ira+6tADgGAUupAl/8iz9uXov2e4cEyb/BKiRSr//fPTDdTZJ1XGRdb7sPVFACm Ok//xo7EMKS5UZM9G8yl3lETiUTS0BN58XAtZpOiYNzX5qg8OV6S7HTDp9DWQRx/GDau fRhESt2hD3uN0r/9ataenR85s8ztVyq5YgDMloSwAqk9jxIOhOMz1gujSH35HgEsD6dX VfEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=J3EioQAm; 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 123sor4978218wml.1.2019.01.02.09.36.18 for (Google Transport Security); Wed, 02 Jan 2019 09:36:18 -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=J3EioQAm; 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=JbDh3nO/eQ5r3H90w51/iWL5ZM5B6uICF84/YZhcCg4=; b=J3EioQAmzqQ510tIYUdGn3niW30hZBCQDaqUxXA6W8Tx56EgefOMxfeiYePggvLtzV duXz2IeiYTCZpxPro8vAGHyjWQH/Y1/d/Ak/b3m9WVFcOtcdpIuYK79GinCB8sSiZtG3 ldCh6avAFDLKYMtq9F3XaB02vQPo22UkXsFhXhyIBx7oOFhnHXxUUD8YJ7FKz6fLxj4g UdEA7DwTWevqPwpxJS3DNw0FJygWBLCgnIL+wZ0Gdd6dAoG2Qh+1ORT2/g8fuq65aSCh hwax2bMe285RhifAqx23AgtZ3ATuL6cdl/MSN8F0BuYYlWJ2a2yf/dyePmmOzCrkGSnZ /Clg== X-Google-Smtp-Source: ALg8bN4dqeXqnEdkw7vZRXClez1sw3njLXNHpEGFyX9nPGsXXD3dzvB0Oz/M0AbKGq7DF3oZ68k8Uw== X-Received: by 2002:a1c:e715:: with SMTP id e21mr36108254wmh.101.1546450578353; Wed, 02 Jan 2019 09:36:18 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:13:8ce:d7fa:9f4c:492]) by smtp.gmail.com with ESMTPSA id t4sm45987076wrm.6.2019.01.02.09.36.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Jan 2019 09:36:17 -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 v2 3/3] kasan: fix krealloc handling for tag-based mode Date: Wed, 2 Jan 2019 18:36:08 +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 --- include/linux/kasan.h | 14 +++++--------- include/linux/slab.h | 4 ++-- mm/kasan/common.c | 20 ++++++++++++-------- mm/slab.c | 8 ++++---- mm/slab_common.c | 2 +- mm/slub.c | 10 +++++----- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index b40ea104dd36..7576fff90923 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -57,9 +57,8 @@ void * __must_check kasan_kmalloc_large(const void *ptr, size_t size, void kasan_kfree_large(void *ptr, unsigned long ip); void kasan_poison_kfree(void *ptr, unsigned long ip); void * __must_check kasan_kmalloc(struct kmem_cache *s, const void *object, - size_t size, gfp_t flags); -void * __must_check kasan_krealloc(const void *object, size_t new_size, - gfp_t flags); + size_t size, gfp_t flags, bool krealloc); +void kasan_krealloc(const void *object, size_t new_size, gfp_t flags); void * __must_check kasan_slab_alloc(struct kmem_cache *s, void *object, gfp_t flags); @@ -118,15 +117,12 @@ static inline void *kasan_kmalloc_large(void *ptr, size_t size, gfp_t flags) static inline void kasan_kfree_large(void *ptr, unsigned long ip) {} static inline void kasan_poison_kfree(void *ptr, unsigned long ip) {} static inline void *kasan_kmalloc(struct kmem_cache *s, const void *object, - size_t size, gfp_t flags) -{ - return (void *)object; -} -static inline void *kasan_krealloc(const void *object, size_t new_size, - gfp_t flags) + size_t size, gfp_t flags, bool krealloc) { return (void *)object; } +static inline void kasan_krealloc(const void *object, size_t new_size, + gfp_t flags) {} static inline void *kasan_slab_alloc(struct kmem_cache *s, void *object, gfp_t flags) diff --git a/include/linux/slab.h b/include/linux/slab.h index d87f913ab4e8..1cd168758c05 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -445,7 +445,7 @@ static __always_inline void *kmem_cache_alloc_trace(struct kmem_cache *s, { void *ret = kmem_cache_alloc(s, flags); - ret = kasan_kmalloc(s, ret, size, flags); + ret = kasan_kmalloc(s, ret, size, flags, false); return ret; } @@ -456,7 +456,7 @@ kmem_cache_alloc_node_trace(struct kmem_cache *s, { void *ret = kmem_cache_alloc_node(s, gfpflags, node); - ret = kasan_kmalloc(s, ret, size, gfpflags); + ret = kasan_kmalloc(s, ret, size, gfpflags, false); return ret; } #endif /* CONFIG_TRACING */ diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 44390392d4c9..b6633ab86160 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -392,7 +392,7 @@ void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, void * __must_check kasan_slab_alloc(struct kmem_cache *cache, void *object, gfp_t flags) { - return kasan_kmalloc(cache, object, cache->object_size, flags); + return kasan_kmalloc(cache, object, cache->object_size, flags, false); } static inline bool shadow_invalid(u8 tag, s8 shadow_byte) @@ -451,7 +451,7 @@ bool kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) } void * __must_check kasan_kmalloc(struct kmem_cache *cache, const void *object, - size_t size, gfp_t flags) + size_t size, gfp_t flags, bool krealloc) { unsigned long redzone_start; unsigned long redzone_end; @@ -468,8 +468,12 @@ void * __must_check kasan_kmalloc(struct kmem_cache *cache, const void *object, redzone_end = round_up((unsigned long)object + cache->object_size, KASAN_SHADOW_SCALE_SIZE); - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) - tag = assign_tag(cache, object, false); + if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) { + if (krealloc) + tag = get_tag(object); + else + tag = assign_tag(cache, object, false); + } /* Tag is ignored in set_tag without CONFIG_KASAN_SW_TAGS */ kasan_unpoison_shadow(set_tag(object, tag), size); @@ -508,19 +512,19 @@ void * __must_check kasan_kmalloc_large(const void *ptr, size_t size, return (void *)ptr; } -void * __must_check kasan_krealloc(const void *object, size_t size, gfp_t flags) +void kasan_krealloc(const void *object, size_t size, gfp_t flags) { struct page *page; if (unlikely(object == ZERO_SIZE_PTR)) - return (void *)object; + return; page = virt_to_head_page(object); if (unlikely(!PageSlab(page))) - return kasan_kmalloc_large(object, size, flags); + kasan_kmalloc_large(object, size, flags); else - return kasan_kmalloc(page->slab_cache, object, size, flags); + kasan_kmalloc(page->slab_cache, object, size, flags, true); } void kasan_poison_kfree(void *ptr, unsigned long ip) diff --git a/mm/slab.c b/mm/slab.c index 73fe23e649c9..09b54386cf67 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3604,7 +3604,7 @@ kmem_cache_alloc_trace(struct kmem_cache *cachep, gfp_t flags, size_t size) ret = slab_alloc(cachep, flags, _RET_IP_); - ret = kasan_kmalloc(cachep, ret, size, flags); + ret = kasan_kmalloc(cachep, ret, size, flags, false); trace_kmalloc(_RET_IP_, ret, size, cachep->size, flags); return ret; @@ -3647,7 +3647,7 @@ void *kmem_cache_alloc_node_trace(struct kmem_cache *cachep, ret = slab_alloc_node(cachep, flags, nodeid, _RET_IP_); - ret = kasan_kmalloc(cachep, ret, size, flags); + ret = kasan_kmalloc(cachep, ret, size, flags, false); trace_kmalloc_node(_RET_IP_, ret, size, cachep->size, flags, nodeid); @@ -3668,7 +3668,7 @@ __do_kmalloc_node(size_t size, gfp_t flags, int node, unsigned long caller) if (unlikely(ZERO_OR_NULL_PTR(cachep))) return cachep; ret = kmem_cache_alloc_node_trace(cachep, flags, node, size); - ret = kasan_kmalloc(cachep, ret, size, flags); + ret = kasan_kmalloc(cachep, ret, size, flags, false); return ret; } @@ -3706,7 +3706,7 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags, return cachep; ret = slab_alloc(cachep, flags, caller); - ret = kasan_kmalloc(cachep, ret, size, flags); + ret = kasan_kmalloc(cachep, ret, size, flags, false); trace_kmalloc(caller, ret, size, cachep->size, flags); diff --git a/mm/slab_common.c b/mm/slab_common.c index 81732d05e74a..b55c58178f83 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1507,7 +1507,7 @@ static __always_inline void *__do_krealloc(const void *p, size_t new_size, ks = ksize(p); if (ks >= new_size) { - p = kasan_krealloc((void *)p, new_size, flags); + kasan_krealloc((void *)p, new_size, flags); return (void *)p; } diff --git a/mm/slub.c b/mm/slub.c index 1e3d0ec4e200..20aa0547acbf 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2763,7 +2763,7 @@ void *kmem_cache_alloc_trace(struct kmem_cache *s, gfp_t gfpflags, size_t size) { void *ret = slab_alloc(s, gfpflags, _RET_IP_); trace_kmalloc(_RET_IP_, ret, size, s->size, gfpflags); - ret = kasan_kmalloc(s, ret, size, gfpflags); + ret = kasan_kmalloc(s, ret, size, gfpflags, false); return ret; } EXPORT_SYMBOL(kmem_cache_alloc_trace); @@ -2791,7 +2791,7 @@ void *kmem_cache_alloc_node_trace(struct kmem_cache *s, trace_kmalloc_node(_RET_IP_, ret, size, s->size, gfpflags, node); - ret = kasan_kmalloc(s, ret, size, gfpflags); + ret = kasan_kmalloc(s, ret, size, gfpflags, false); return ret; } EXPORT_SYMBOL(kmem_cache_alloc_node_trace); @@ -3364,7 +3364,7 @@ static void early_kmem_cache_node_alloc(int node) init_tracking(kmem_cache_node, n); #endif n = kasan_kmalloc(kmem_cache_node, n, sizeof(struct kmem_cache_node), - GFP_KERNEL); + GFP_KERNEL, false); page->freelist = get_freepointer(kmem_cache_node, n); page->inuse = 1; page->frozen = 0; @@ -3779,7 +3779,7 @@ void *__kmalloc(size_t size, gfp_t flags) trace_kmalloc(_RET_IP_, ret, size, s->size, flags); - ret = kasan_kmalloc(s, ret, size, flags); + ret = kasan_kmalloc(s, ret, size, flags, false); return ret; } @@ -3823,7 +3823,7 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node) trace_kmalloc_node(_RET_IP_, ret, size, s->size, flags, node); - ret = kasan_kmalloc(s, ret, size, flags); + ret = kasan_kmalloc(s, ret, size, flags, false); return ret; }