Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp148809rdb; Sun, 21 Jan 2024 22:31:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHFeqfmSBBLOzYEwZY0WgZaoK3Ft5vM+pz5KKIHZfnTL7XU59HZDxTvrjcQIqL1n5blkBq8 X-Received: by 2002:a05:6214:1c0f:b0:685:caed:934f with SMTP id u15-20020a0562141c0f00b00685caed934fmr4128037qvc.58.1705905073228; Sun, 21 Jan 2024 22:31:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705905073; cv=pass; d=google.com; s=arc-20160816; b=YpOSApPjwtZoKY7o1LiqcWeWlDCiHLatO8K1SrITVsoMFJWpFmOEmRhxdYkXn940BS deWajZj0phPyNNrjpUabnWou4QLxot/nmESlX2jNozYBZwZresdJ7u2n+DJ5B/B1Nj6K TBnuhM7gAEBVFxbQVAMo7tLAg3wPVvkKFuqnvFxpSgW4czrnCAtxrx7SO40LuiJDZDWJ pTVo9LFjYQIVyRodw+turmftXPnEYIpIr0PZMtXIyy4nxCrG0EM5CTWryxIfQ2fIeP8L LS6Ag3Xl+1oEOOgdRbLB2Zhrjh2eSjp1AXv5EoTNsbizTHjKqA6LxF1HCI1IKw8BrXWk e1Dg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=nytfd9cYSxIzkyb46ALEhPTR7VNtLMYQD9eRRWGEn5M=; fh=yzfLLNesB6r6TjQr/FuRoDBhjz/bbTdqaOUUV/WZHrE=; b=eBuhi4P3rP8HHv2nGKV86P0zqM5vsULCuptg5ecQKTS/lomElrxd7AlCcUna0N1Qmv sFmY80K1Elu8RHE0gVKg1lPIgjY4p7DEZEPZjC7XfO7nT0qkbezhtC8paiRIHrXC/2DH a+WOepneQ8LBHx/aPHp2hQbq1yjKio+3T5I7c6B6OisdJ621RSnfnK/pHxGd7NAdNhje Jj6D9/Dfucb3WW2sSoGBo+xvKnAVkH77eZcEJ55Sbi601Ch4vP1+PM6hvC3Hyt+LarzE do4cXqDyJ2AhoxRN/+7Y7NgEg8+MYtWsqBGuSF4U62gU6Zt5N/O5nK8Zkj1z4YeXsaQI L6bA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Cq5jQMg4; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-32388-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32388-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d13-20020a0cb2cd000000b006819995dec8si5112853qvf.251.2024.01.21.22.31.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 22:31:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32388-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Cq5jQMg4; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-32388-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32388-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 145611C224E9 for ; Mon, 22 Jan 2024 06:31:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 813AE6ADB; Mon, 22 Jan 2024 06:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Cq5jQMg4" Received: from out-184.mta1.migadu.com (out-184.mta1.migadu.com [95.215.58.184]) (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 AD511F9C8 for ; Mon, 22 Jan 2024 06:30:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705905061; cv=none; b=uGBAoc1YGD1KVLzjrvZeWKkZUsRsQgOHV9nJMoNSAwjojwKdyh4WbW9qXDfWUghaOxyUAFPUxkXaH3/W5q+tYU09E9rhr+qJi6/U5pdZOstPGwj0PJ6JGd7iWi0WZIw8ecMO7LOx8jQ1cAN4FTQaTc3WIPBM0mt+NHFpWB7CJJo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705905061; c=relaxed/simple; bh=SScfUi//C5ZYNhcwl0wIXUFZfCGhL7nQm00JYt9e7N0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=dQ2Lv1bHQFrqpDySQCoqEm5z2zsIkSgOyrBTmuu4EaTI7zjKRD3/noDZcn4rd9HO0eHTiTGLSY/9128IOMHhaz6tlh927h1/uS6GRF/MsryvnF26syI9zNwFyJHrfxu6Bq3TZG8/bJ+hi7Uu84JN5S5y+L+RdvDU1oi7B3+tdO4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Cq5jQMg4; arc=none smtp.client-ip=95.215.58.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1705905056; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nytfd9cYSxIzkyb46ALEhPTR7VNtLMYQD9eRRWGEn5M=; b=Cq5jQMg4ZAFODSMDK8JV6WQCwADbpvDLfmKgEX2Y0ozYYBbkUg1H49x4UX2VfSlpBADREq /3pVQI0QX4ct7hXCJor0Bc7A+RRVpi4IB4UCuybNxiDK39jl9Y0asN9MfMtKYt7Vj3rnEt 8PWV7KEym7GDqQZlf3iTcTFJZX2cyHo= Date: Sun, 21 Jan 2024 22:30:47 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf 3/3] selftest/bpf: Test the read of vsyscall page under x86-64 Content-Language: en-GB To: Hou Tao , x86@kernel.org, bpf@vger.kernel.org Cc: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , linux-kernel@vger.kernel.org, xingwei lee , Jann Horn , houtao1@huawei.com References: <20240119073019.1528573-1-houtao@huaweicloud.com> <20240119073019.1528573-4-houtao@huaweicloud.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yonghong Song In-Reply-To: <20240119073019.1528573-4-houtao@huaweicloud.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 1/18/24 11:30 PM, Hou Tao wrote: > From: Hou Tao > > Using bpf_probe_read_kernel{_str}() or bpf_probe_read{_str}() to read > from vsyscall page under x86-64 will trigger oops, so add one test case > to ensure that the problem is fixed. > > Beside those four bpf helpers mentioned above, testing the read of > vsyscall page by using bpf_probe_read_user{_str} and > bpf_copy_from_user{_task}() as well. > > vsyscall page could be disabled by CONFIG_LEGACY_VSYSCALL_NONE or > vsyscall=none boot cmd-line, but it doesn't affect the reproduce of the > problem and the returned error codes. > > Signed-off-by: Hou Tao > --- > .../selftests/bpf/prog_tests/read_vsyscall.c | 61 +++++++++++++++++++ > .../selftests/bpf/progs/read_vsyscall.c | 45 ++++++++++++++ > 2 files changed, 106 insertions(+) > create mode 100644 tools/testing/selftests/bpf/prog_tests/read_vsyscall.c > create mode 100644 tools/testing/selftests/bpf/progs/read_vsyscall.c > > diff --git a/tools/testing/selftests/bpf/prog_tests/read_vsyscall.c b/tools/testing/selftests/bpf/prog_tests/read_vsyscall.c > new file mode 100644 > index 0000000000000..d9247cc89cf3e > --- /dev/null > +++ b/tools/testing/selftests/bpf/prog_tests/read_vsyscall.c > @@ -0,0 +1,61 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* Copyright (C) 2024. Huawei Technologies Co., Ltd */ > +#include "test_progs.h" > +#include "read_vsyscall.skel.h" > + > +#if defined(__x86_64__) > +/* For VSYSCALL_ADDR */ > +#include > +#else > +/* To prevent build failure on non-x86 arch */ > +#define VSYSCALL_ADDR 0UL > +#endif > + > +struct read_ret_desc { > + const char *name; > + int ret; > +} all_read[] = { > + { .name = "probe_read_kernel", .ret = -ERANGE }, > + { .name = "probe_read_kernel_str", .ret = -ERANGE }, > + { .name = "probe_read", .ret = -ERANGE }, > + { .name = "probe_read_str", .ret = -ERANGE }, > + /* __access_ok() will fail */ > + { .name = "probe_read_user", .ret = -EFAULT }, > + /* __access_ok() will fail */ > + { .name = "probe_read_user_str", .ret = -EFAULT }, > + /* access_ok() will fail */ > + { .name = "copy_from_user", .ret = -EFAULT }, > + /* both vma_lookup() and expand_stack() will fail */ > + { .name = "copy_from_user_task", .ret = -EFAULT }, The above comments are not clear enough. For example, '__access_ok() will fail', user will need to check the source code where __access_ok() is and this could be hard e.g., for probe_read_user_str(). Another example, 'both vma_lookup() and expand_stack() will fail', where is vma_lookup()/expand_stack()? User needs to further check to make sense. I suggest remove the above comments and add more detailed explanation in commit messages with callstack indicating where the fail/error return happens. > +}; > + > +void test_read_vsyscall(void) > +{ > + struct read_vsyscall *skel; > + unsigned int i; > + int err; > + > +#if !defined(__x86_64__) > + test__skip(); > + return; > +#endif > + skel = read_vsyscall__open_and_load(); > + if (!ASSERT_OK_PTR(skel, "read_vsyscall open_load")) > + return; > + > + skel->bss->target_pid = getpid(); > + err = read_vsyscall__attach(skel); > + if (!ASSERT_EQ(err, 0, "read_vsyscall attach")) > + goto out; > + > + /* userspace may don't have vsyscall page due to LEGACY_VSYSCALL_NONE, > + * but it doesn't affect the returned error codes. > + */ > + skel->bss->user_ptr = (void *)VSYSCALL_ADDR; > + usleep(1); > + > + for (i = 0; i < ARRAY_SIZE(all_read); i++) > + ASSERT_EQ(skel->bss->read_ret[i], all_read[i].ret, all_read[i].name); > +out: > + read_vsyscall__destroy(skel); > +} [...]