Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2819939pxb; Tue, 13 Apr 2021 10:54:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5p/i1a10TajSR9nmkznwDWT0cmpNSl4F7dcLDUN5zlZyoKk7PqTTQfu2WjMnJzjT5eKNU X-Received: by 2002:a05:6402:b26:: with SMTP id bo6mr37776674edb.162.1618336498602; Tue, 13 Apr 2021 10:54:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618336498; cv=none; d=google.com; s=arc-20160816; b=nPrh5He/mYaUfPDLQ1+E7lkOdp5tDpDMgU8VX8bn0cBWUiZnI9T0uurQJU2hKjmCNd 1f1S/Y9FzfmoGYiBzjx2/SwRRl5bxYAt2r4+dUi1n5wgMFC5YAav9eCJm5GRWb+DnaFC 2bRBrn8NJUtCJD5KKnblyzPARYqpULmLRmcE3yBIY5UVM/EzY4riYUhCuU/sG+eUkdLV QyKMNaJCBw5GXrJyKazuSRDvJgO9dMYm/KqLdfz0aeif3tHF7ekanPqoJi2AziacRxGs hW0U1GChK/Jqolzv7NXJ2e98HTBkZj8qZyicuDHcJurpLYFYy4M/apGCnMnrjgX6ATIw Id/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=6C4vWMiZx7mN3igKhLzmPaGuqZegAp9MdSTAPom4xGU=; b=jbWsg1iEcen8IsVfQEUk0wN8G7QrVxYdrnEhLXG+jIH+h0SOd0oUTJrL7DQRzPwYhp tK4IwyN5JejCXmCJYj7m3dpmiToTlEKuZD/iu4wb4U/V+xFKEyOOYYWezMUfKvwkLcfa tLfrnQOopnC+M0ybBJyBQP63nc2pF5CohwygbTzEC32c1yt1bain16pWtEluwlVxhwL8 roXaRa7y2LU7pj62a8OgCCwKgw7St9rDzOP7S3JkCVIDdq6w7PwxAP0lvqx+gWhoPDwz m3yqlSP5BXYcCFU9iPeEVLrs5JS849HOGqf1BfynJa9EvM4XS0FppVvre2rOrLWtZlGj Q0AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="iQR/H1LP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u1si10601676ejg.28.2021.04.13.10.54.35; Tue, 13 Apr 2021 10:54:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="iQR/H1LP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240383AbhDMNAy (ORCPT + 99 others); Tue, 13 Apr 2021 09:00:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:53186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230472AbhDMNAx (ORCPT ); Tue, 13 Apr 2021 09:00:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 54F81613BB; Tue, 13 Apr 2021 13:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618318834; bh=cJd5gEKEKaZSb9uFKqHIAHqh5CE9Y1iKpOsW8fH1KSk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=iQR/H1LP/GdJDQUYi5kjAAP9crEBzsMZfaMzLuOPVawZNgAUFNI8uuTtB2FDJn9fQ xzW5xqrCr6rRDSwE56e2SqFhAeJ7ceL3y94QB6v2p8YGoijBxi2TgRJ6fueOkbKAv7 dqmmCfB8iTejc7P8dQFboT7BHRCuiC0CNEaLn5uYZy+WdKq3/TkgfaEeWDMOIy1dfZ yy5U1bxm6dcEQEUPLVdWbHHQjCnlZCb2v6jwunaeElw8xj8YN1PWYgSexHvp0vgyot qDJtBcPYn9B9ea5snujOpivE0urYT/np4yYMq+NkLJ4uhGxxZpVCFEiWIVR/zlZV3N 39BR02j3p8PQw== Date: Tue, 13 Apr 2021 22:00:30 +0900 From: Masami Hiramatsu To: Jisheng Zhang Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Jiri Olsa , linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/kprobes: Simplify alloc_insn_page() with __vmalloc_node_range Message-Id: <20210413220030.d1cbbc63659dcbc52876696d@kernel.org> In-Reply-To: <20210413180231.19b72601@xhacker.debian> References: <20210413180231.19b72601@xhacker.debian> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Tue, 13 Apr 2021 18:03:24 +0800 Jisheng Zhang wrote: > Use the __vmalloc_node_range() to simplify x86's alloc_insn_page() > implementation. Have you checked this is equivarent to the original code on all architecture? IIRC, some arch has a special module_alloc(), thus I NACKed similar patch previously. Thank you, > > Signed-off-by: Jisheng Zhang > --- > arch/x86/kernel/kprobes/core.c | 24 ++++-------------------- > 1 file changed, 4 insertions(+), 20 deletions(-) > > diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c > index df776cdca327..75081f3dbe44 100644 > --- a/arch/x86/kernel/kprobes/core.c > +++ b/arch/x86/kernel/kprobes/core.c > @@ -383,26 +383,10 @@ static int prepare_boost(kprobe_opcode_t *buf, struct kprobe *p, > /* Make page to RO mode when allocate it */ > void *alloc_insn_page(void) > { > - void *page; > - > - page = module_alloc(PAGE_SIZE); > - if (!page) > - return NULL; > - > - set_vm_flush_reset_perms(page); > - /* > - * First make the page read-only, and only then make it executable to > - * prevent it from being W+X in between. > - */ > - set_memory_ro((unsigned long)page, 1); > - > - /* > - * TODO: Once additional kernel code protection mechanisms are set, ensure > - * that the page was not maliciously altered and it is still zeroed. > - */ > - set_memory_x((unsigned long)page, 1); > - > - return page; > + return __vmalloc_node_range(PAGE_SIZE, PAGE_SIZE, VMALLOC_START, > + VMALLOC_END, GFP_KERNEL, PAGE_KERNEL_ROX, > + VM_FLUSH_RESET_PERMS, NUMA_NO_NODE, > + __builtin_return_address(0)); > } > > /* Recover page to RW mode before releasing it */ > -- > 2.31.0 > -- Masami Hiramatsu