From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2BB9C433F5 for ; Mon, 13 Dec 2021 22:16:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 652046B0083; Mon, 13 Dec 2021 16:59:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 600526B00A3; Mon, 13 Dec 2021 16:59:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C7706B0087; Mon, 13 Dec 2021 16:59:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0089.hostedemail.com [216.40.44.89]) by kanga.kvack.org (Postfix) with ESMTP id 3A4236B0082 for ; Mon, 13 Dec 2021 16:59:57 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 025E21807EE90 for ; Mon, 13 Dec 2021 21:59:47 +0000 (UTC) X-FDA: 78914138814.19.2F00E67 Received: from mail-il1-f177.google.com (mail-il1-f177.google.com [209.85.166.177]) by imf25.hostedemail.com (Postfix) with ESMTP id 37027A0018 for ; Mon, 13 Dec 2021 21:59:43 +0000 (UTC) Received: by mail-il1-f177.google.com with SMTP id m12so3316542ild.0 for ; Mon, 13 Dec 2021 13:59:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BNW1RvPQZwm1C5HKSe2mnjCE7ya9sQIsxIsz8L3X9Xo=; b=AFw0EAZVYhtZb0kjOzExWi8L294KFToI1Em3urGtFjSQd9JkW7HjFQ4iOp6lcdkTDs s0KIuURm3rHMjTYCFxnzDKQlNvw3GNad4PAvf/7jFd0feQzei3a80L5AQbp4+2nUsdZl jZCgp9p/1Hr6AnkKBZ/OE1bWN7IZ7Gi7ubTdEccmlU882chctjUEhw64P7vq+pjGuqav ubgjskP7/39W6k9MPSe/ZFUrtf+cQ9W0v0CyU3bo8wOW2z6VdIVHpYaRBoAxMkywbiAE 110JqPwMiLmJyFXVjTlD3G9dQZRWEn/fptDxE9Yddf6QBLjRbFg7PPH0dnQswAHxQktH XVhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BNW1RvPQZwm1C5HKSe2mnjCE7ya9sQIsxIsz8L3X9Xo=; b=I06uoouGpfptuveUZgNR6MyeKC0Ou35n3+/58iahDP8MohE2cuZgaFL1r7FdUvUFP6 HfnZk8QZ2VJW8m7tMp8bYw5jAHQlduBB2utcTV55Fnr/088lSUBVwkwccHSYQlBEmIgu Vl9IYph4dr1YlaNCUuTXLPJX3P5aZ1raxCCFMPJF5Yk0rkYMbAuZFs64YQI3Z6tl2sre 9yWGMy2DiG+VOXjrfsgbHLp3AlQuu32+K0jOyVT99tWWr+n4Satx7elcnFUKcR3nc2Il iwOfedZthAc93SM0whsTpuIZDejnbpUJMDi8gEqpoFjYzTrnFH4UXFgIVpI5+z4Gp36s S5Bg== X-Gm-Message-State: AOAM5328zMyuWxIE/LsAoyVqcTLEetHhJ97rfdbSSE4GTzx8MML83RBw mV9YkVed3mGIAyiswp7nM932P2goJWYwvrxMRwI= X-Google-Smtp-Source: ABdhPJw/1rN4lq8DuEoGuVwsZabrwHwTtkKTIszhbJcLxpcHOEkIJwhJK1EKrYh44rTOBDgVCMPkoPzceaTP/CJTLBA= X-Received: by 2002:a05:6e02:f07:: with SMTP id x7mr921673ilj.28.1639432785937; Mon, 13 Dec 2021 13:59:45 -0800 (PST) MIME-Version: 1.0 References: <4a5ec956a2666c1f967c9789534a8ac4d4fe26f9.1639432170.git.andreyknvl@google.com> In-Reply-To: <4a5ec956a2666c1f967c9789534a8ac4d4fe26f9.1639432170.git.andreyknvl@google.com> From: Andrey Konovalov Date: Mon, 13 Dec 2021 22:59:35 +0100 Message-ID: Subject: Re: [PATCH mm v3 31/38] kasan, arm64: don't tag executable vmalloc allocations To: Vincenzo Frascino , Catalin Marinas Cc: Marco Elver , Alexander Potapenko , Andrew Morton , Dmitry Vyukov , Andrey Ryabinin , kasan-dev , Linux Memory Management List , Will Deacon , Mark Rutland , Linux ARM , Peter Collingbourne , Evgenii Stepanov , LKML , Andrey Konovalov , andrey.konovalov@linux.dev Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: m38u1331owa4yo9u1ysumoqbx5bmct3z Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AFw0EAZV; spf=pass (imf25.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.166.177 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 37027A0018 X-HE-Tag: 1639432783-761110 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: On Mon, Dec 13, 2021 at 10:55 PM wrote: > > From: Andrey Konovalov > > Besides asking vmalloc memory to be executable via the prot argument > of __vmalloc_node_range() (see the previous patch), the kernel can skip > that bit and instead mark memory as executable via set_memory_x(). > > Once tag-based KASAN modes start tagging vmalloc allocations, executing > code from such allocations will lead to the PC register getting a tag, > which is not tolerated by the kernel. > > Generic kernel code typically allocates memory via module_alloc() if > it intends to mark memory as executable. (On arm64 module_alloc() > uses __vmalloc_node_range() without setting the executable bit). > > Thus, reset pointer tags of pointers returned from module_alloc(). > > However, on arm64 there's an exception: the eBPF subsystem. Instead of > using module_alloc(), it uses vmalloc() (via bpf_jit_alloc_exec()) > to allocate its JIT region. > > Thus, reset pointer tags of pointers returned from bpf_jit_alloc_exec(). > > Signed-off-by: Andrey Konovalov > > --- > > Changes v2->v3: > - Add this patch. > --- > arch/arm64/kernel/module.c | 3 ++- > arch/arm64/net/bpf_jit_comp.c | 3 ++- > 2 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c > index d3a1fa818348..f2d4bb14bfab 100644 > --- a/arch/arm64/kernel/module.c > +++ b/arch/arm64/kernel/module.c > @@ -63,7 +63,8 @@ void *module_alloc(unsigned long size) > return NULL; > } > > - return p; > + /* Memory is intended to be executable, reset the pointer tag. */ > + return kasan_reset_tag(p); > } > > enum aarch64_reloc_op { > diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c > index 07aad85848fa..381a67922c2d 100644 > --- a/arch/arm64/net/bpf_jit_comp.c > +++ b/arch/arm64/net/bpf_jit_comp.c > @@ -1147,7 +1147,8 @@ u64 bpf_jit_alloc_exec_limit(void) > > void *bpf_jit_alloc_exec(unsigned long size) > { > - return vmalloc(size); > + /* Memory is intended to be executable, reset the pointer tag. */ > + return kasan_reset_tag(vmalloc(size)); > } > > void bpf_jit_free_exec(void *addr) > -- > 2.25.1 > Catalin, Vincenzo, This is a new patch added in v3. Could you PTAL? Thanks!