Message ID | 20240202103935.3154011-1-houtao@huaweicloud.com |
---|---|
Headers |
Return-Path: <linux-kernel+bounces-49682-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp336778dyc; Fri, 2 Feb 2024 02:39:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEc+AhjtLlHsL7akxPezKCcya4980LRiKAKg5J/g/12ct8jY5qwcGEN/Q6AAIJOz3AXQWIE X-Received: by 2002:a25:c7d4:0:b0:dc2:53ad:9a3f with SMTP id w203-20020a25c7d4000000b00dc253ad9a3fmr1754241ybe.27.1706870355105; Fri, 02 Feb 2024 02:39:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706870355; cv=pass; d=google.com; s=arc-20160816; b=cDDdrNvTZdZhXxg2c3O5HsZJqq52g2n1Tq8fPX+N8dc2lnL33vduAnqGK5mo8Ksyo2 hJ1QO2AqsFVS08CrEXS7utmnlQMY8Qctp6qQO2Q62z9Yb9ZyYWxTW91i4k4Tm6CsGO2k B2NJ12+ZPHbuFI52gITfzvrBEq8ZuVHljWJcRT9l6bgwlQ1HHUbJbqX1mMifWSkVeNzj B2UeihfAymg5wIcqk92UT0DlFrB/Agk3wLHVac5zH0NKi5EMRP+FuZIjIUp4BK1nN9VP DGF6brLNahYqQEWgcSkNObrFQG4gCxOpTQvx0PxussVwohGitC0Sw51sGsjCilPEOpQL m0Yg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=TuIJQnPgcO8SN6fxUCtYXwckBbi015wFs75O54XFSKY=; fh=wx5TCzbx/ioTymhBXd5GkuJrUFTcs0AsEGEHmRB2PX8=; b=R9pvTbMQ0PHYyuHffLeiC55ZFmwVIuk/z0TFaSSFrR7v0M9W4QCuSBiDwIsko3fidB YXqGIBbAECWhMzkeJQen/pznXj1oFiaoNSbp0OLHjSaBfBBfP6Z/DSOg+ycX+skQH35c Kb3NrnfGERz4lx+d0me8gPXPndQpkYT0IMhJNxjUVr7EtDY3w5mlQ5Z8dv8QGFvPHZhv Nhq4K7BiHqRMS8Rntx1oBhTXZ9/XyAoGbN0pKVS3bptBCqJAhMCc/2GZ8ex2YkuTqnvW Xf2ipauSHRl50fGWHdtLhumPBtH457+CCE6nkfLpl43/BZcb83WcCFgWuZw+pz4cwQnz 4W3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-49682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49682-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWv9vyR1F+j9Nzlww5Fu0+z/U7ViWBl34KWMlqSX5jQ43zAnCN9ce2UxIxNyL1zQaqbVSmUT9cXfFUBBKmX5WVP3nSULg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ph11-20020a0562144a4b00b0068c56b565e7si1612847qvb.270.2024.02.02.02.39.14 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 02:39:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-49682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49682-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DD4881C24474 for <ouuuleilei@gmail.com>; Fri, 2 Feb 2024 10:39:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66A1313DB80; Fri, 2 Feb 2024 10:38:51 +0000 (UTC) Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60B8F83CCF; Fri, 2 Feb 2024 10:38:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706870329; cv=none; b=tb9PXzon8I0cNe+m2Eh50jqhyLkeGG0e8zKHLxpRcSIViPHK51Ol60R0rNHeinLCHJwny4G/HY9lbLFIjEF/OVd+v1ptVwfWPhmkJ3gN8JwZpD4nM3ry/P5zPg4EVMYK/KLm7qiBItE9/6sM2gt2lqwr1bcOKXjCdtC4BU7So8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706870329; c=relaxed/simple; bh=cnDf1jgcpDPZn8ij0QoMY0mj0HYfc1ekDOk+ej5HHbs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=QcH56qq04lgWUI+Mzr5jJp9su8Z4dnmvWz+J4vSlUGJpXZk7brtWCVGtAvwdO4baoErXxG9DTkJBQIImXID+fvnaDLtkzNy0RaJfrHWKH9BWmYA9OP5nyKZJgbd1vsPVemfCAXTf5tNhAZ9AXNeUJN7r9Ct88vZvJZTfFuUtJpQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TRC1C3mpGz4f3kFj; Fri, 2 Feb 2024 18:38:39 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id C07F41A027B; Fri, 2 Feb 2024 18:38:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP1 (Coremail) with SMTP id cCh0CgAn+REwxrxl46r1Cg--.15879S4; Fri, 02 Feb 2024 18:38:42 +0800 (CST) From: Hou Tao <houtao@huaweicloud.com> To: x86@kernel.org, bpf@vger.kernel.org Cc: Dave Hansen <dave.hansen@linux.intel.com>, Andy Lutomirski <luto@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, "H . Peter Anvin" <hpa@zytor.com>, linux-kernel@vger.kernel.org, xingwei lee <xrivendell7@gmail.com>, Jann Horn <jannh@google.com>, Sohil Mehta <sohil.mehta@intel.com>, Yonghong Song <yonghong.song@linux.dev>, houtao1@huawei.com Subject: [PATCH bpf v3 0/3] Fix the read of vsyscall page through bpf Date: Fri, 2 Feb 2024 18:39:32 +0800 Message-Id: <20240202103935.3154011-1-houtao@huaweicloud.com> X-Mailer: git-send-email 2.29.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kern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r0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07UZ18PUUUUU= X-CM-SenderInfo: xkrx3t3r6k3tpzhluzxrxghudrp/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789783289723080493 X-GMAIL-MSGID: 1789783289723080493 |
Series |
Fix the read of vsyscall page through bpf
|
|
Message
Hou Tao
Feb. 2, 2024, 10:39 a.m. UTC
From: Hou Tao <houtao1@huawei.com>
Hi,
As reported by syzboot [1] and [2], when trying to read vsyscall page
by using bpf_probe_read_kernel() or bpf_probe_read(), oops may happen.
Thomas Gleixner had proposed a test patch [3], but it seems that no
formal patch is posted after about one month [4], so I post it instead
and add an Originally-by tag in patch #2.
Patch #1 makes is_vsyscall_vaddr() being a common helper. Patch #2 fixes
the problem by disallowing vsyscall page read for
copy_from_kernel_nofault(). Patch #3 adds one test case to ensure the
read of vsyscall page through bpf is rejected. Please see individual
patches for more details.
Comments are always welcome.
[1]: https://lore.kernel.org/bpf/CAG48ez06TZft=ATH1qh2c5mpS5BT8UakwNkzi6nvK5_djC-4Nw@mail.gmail.com/
[2]: https://lore.kernel.org/bpf/CABOYnLynjBoFZOf3Z4BhaZkc5hx_kHfsjiW+UWLoB=w33LvScw@mail.gmail.com/
[3]: https://lore.kernel.org/bpf/87r0jwquhv.ffs@tglx/
[4]: https://lore.kernel.org/bpf/e24b125c-8ff4-9031-6c53-67ff2e01f316@huaweicloud.com/
Change Log:
v3:
* rephrase commit message for patch #1 & #2 (Sohil)
* reword comments in copy_from_kernel_nofault_allowed() (Sohil)
* add Rvb tag for patch #1 and Acked-by tag for patch #3 (Sohil, Yonghong)
v2: https://lore.kernel.org/bpf/20240126115423.3943360-1-houtao@huaweicloud.com/
* move is_vsyscall_vaddr to asm/vsyscall.h instead (Sohil)
* elaborate on the reason for disallowing of vsyscall page read in
copy_from_kernel_nofault_allowed() (Sohil)
* update the commit message of patch #2 to more clearly explain how
the oops occurs. (Sohil)
* update the commit message of patch #3 to explain the expected return
values of various bpf helpers (Yonghong)
v1: https://lore.kernel.org/bpf/20240119073019.1528573-1-houtao@huaweicloud.com/
Hou Tao (3):
x86/mm: Move is_vsyscall_vaddr() into asm/vsyscall.h
x86/mm: Disallow vsyscall page read for copy_from_kernel_nofault()
selftest/bpf: Test the read of vsyscall page under x86-64
arch/x86/include/asm/vsyscall.h | 10 ++++
arch/x86/mm/fault.c | 9 ---
arch/x86/mm/maccess.c | 10 ++++
.../selftests/bpf/prog_tests/read_vsyscall.c | 57 +++++++++++++++++++
.../selftests/bpf/progs/read_vsyscall.c | 45 +++++++++++++++
5 files changed, 122 insertions(+), 9 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/read_vsyscall.c
create mode 100644 tools/testing/selftests/bpf/progs/read_vsyscall.c
Comments
Hello: This series was applied to bpf/bpf.git (master) by Alexei Starovoitov <ast@kernel.org>: On Fri, 2 Feb 2024 18:39:32 +0800 you wrote: > From: Hou Tao <houtao1@huawei.com> > > Hi, > > As reported by syzboot [1] and [2], when trying to read vsyscall page > by using bpf_probe_read_kernel() or bpf_probe_read(), oops may happen. > > [...] Here is the summary with links: - [bpf,v3,1/3] x86/mm: Move is_vsyscall_vaddr() into asm/vsyscall.h https://git.kernel.org/bpf/bpf/c/ee0e39a63b78 - [bpf,v3,2/3] x86/mm: Disallow vsyscall page read for copy_from_kernel_nofault() https://git.kernel.org/bpf/bpf/c/32019c659ecf - [bpf,v3,3/3] selftest/bpf: Test the read of vsyscall page under x86-64 https://git.kernel.org/bpf/bpf/c/be66d79189ec You are awesome, thank you!