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 6EC58C433EF for ; Mon, 20 Dec 2021 22:05:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2E6D6B00AA; Mon, 20 Dec 2021 17:05:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DB83F6B00AB; Mon, 20 Dec 2021 17:05:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0AB96B00AC; Mon, 20 Dec 2021 17:05:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0026.hostedemail.com [216.40.44.26]) by kanga.kvack.org (Postfix) with ESMTP id ABAAF6B00AA for ; Mon, 20 Dec 2021 17:05:16 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 701E689D4D for ; Mon, 20 Dec 2021 22:05:16 +0000 (UTC) X-FDA: 78939554232.01.0D45DA7 Received: from mail-il1-f172.google.com (mail-il1-f172.google.com [209.85.166.172]) by imf07.hostedemail.com (Postfix) with ESMTP id 0221640049 for ; Mon, 20 Dec 2021 22:05:15 +0000 (UTC) Received: by mail-il1-f172.google.com with SMTP id l5so8694262ilv.7 for ; Mon, 20 Dec 2021 14:05:15 -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=5Hk8y3FD8xJfm6RryiwKYMpYBDu8nYDhrS0Z2nhR5mA=; b=Zab6bdqgsKpO/zQHt+XcX2McS19UTV7AO/xgbFVS71bQM/pdfVeLhUfqVN9sbQwrYi UQRVvcptR4po4cGi4gGflZ2MwNW+R7g7+LApOjTh1u4bYS4/O6eKEcwLK3DYDwbgzQ/E WBXRoPSz9gLS+Fq6VBM8zBLcY8p0bm8HTH4D3SlMwqDu7196S7+iLZAE9GwvW2HVsk9+ OajY7HJWg9NoHGWKpa0gtiSlK5VJ1PYud1yDl8KhKAnqJozT2oD7+dZkUT2kQTYUn+Qh X6agFgDTcpdwfw7izJoxE9P25nDqACdQuj/WNVMEv5dSaO/YEe3jnAQOizboCyml5rcr +bjQ== 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=5Hk8y3FD8xJfm6RryiwKYMpYBDu8nYDhrS0Z2nhR5mA=; b=ktyQn+/OHvUX24RDHt+h7z7wzIGBJll+VLX//jfXFOmnxbD6GSCgKBMT3qSPnmATId l2AOFC9xG9fimWU8iC895CbQ8wtQXdrSZH2wEwpMCPtX4CeXhf1dpRP6p7UU010RFunt GYadwBKZkWQ+/XE2kDkfo+AaIAu5aMC0UN4OuLDKSeDOOwi3ztNRQktnCBxcGExZUNs9 b9fOtTDP0bSwjGMsX12IbAofGgZBTud+uoDxTondTpYmJe8oNMdYUh1GHqYYpqEDWwnF pDRewkwOmLbwl0WdH2AxS9CEzkUD+saziYlNFHN9tekIAeSBlYKyHaXET6PNm+kpsFRA cvDA== X-Gm-Message-State: AOAM531tmAL+16P784RVNzS7AP5g871dGyvMwRRjWv6pWwlqkoitXgrG zKKZ/gd4xiD7m++NPPrEoiVEM3p+xQNGq3YEVEE= X-Google-Smtp-Source: ABdhPJzbEqrJ5y5giLAK2HsSF+gca53GPFIF+26Au4MRdQDxf+RBp07h+hyXC7+c0b4HcvLGOf9GPlX21+NDcLtg7FM= X-Received: by 2002:a05:6e02:178f:: with SMTP id y15mr19677ilu.235.1640037915336; Mon, 20 Dec 2021 14:05:15 -0800 (PST) MIME-Version: 1.0 References: <85ecef50788a3915a9a8fb52e97207901f27b057.1640036051.git.andreyknvl@google.com> In-Reply-To: <85ecef50788a3915a9a8fb52e97207901f27b057.1640036051.git.andreyknvl@google.com> From: Andrey Konovalov Date: Mon, 20 Dec 2021 23:05:04 +0100 Message-ID: Subject: Re: [PATCH mm v4 32/39] kasan, arm64: don't tag executable vmalloc allocations To: Catalin Marinas Cc: Marco Elver , Alexander Potapenko , Andrew Morton , Dmitry Vyukov , Andrey Ryabinin , kasan-dev , Linux Memory Management List , Vincenzo Frascino , 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-Rspamd-Queue-Id: 0221640049 X-Stat-Signature: kaox8nfekjmn13uqhy69py6y4bgr333t Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Zab6bdqg; spf=pass (imf07.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.166.172 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam10 X-HE-Tag: 1640037915-396229 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 20, 2021 at 11:02 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(). > > Resetting tags for these pointers results in untagged pointers being > passed to set_memory_x(). This causes conflicts in arithmetic checks > in change_memory_common(), as vm_struct->addr pointer returned by > find_vm_area() is tagged. > > Reset pointer tag of find_vm_area(addr)->addr in change_memory_common(). > > Signed-off-by: Andrey Konovalov > > --- > > Changes v3->v4: > - Reset pointer tag in change_memory_common(). > > Changes v2->v3: > - Add this patch. > --- > arch/arm64/kernel/module.c | 3 ++- > arch/arm64/mm/pageattr.c | 2 +- > arch/arm64/net/bpf_jit_comp.c | 3 ++- > 3 files changed, 5 insertions(+), 3 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/mm/pageattr.c b/arch/arm64/mm/pageattr.c > index a3bacd79507a..64e985eaa52d 100644 > --- a/arch/arm64/mm/pageattr.c > +++ b/arch/arm64/mm/pageattr.c > @@ -85,7 +85,7 @@ static int change_memory_common(unsigned long addr, int numpages, > */ > area = find_vm_area((void *)addr); > if (!area || > - end > (unsigned long)area->addr + area->size || > + end > (unsigned long)kasan_reset_tag(area->addr) + area->size || > !(area->flags & VM_ALLOC)) > return -EINVAL; > > 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 Hi Catalin, I had to change this patch to fix an issue I discovered during testing. Could you PTAL once again? Thanks!