Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp742399rdb; Fri, 2 Feb 2024 02:38:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHth8UbOdzCPYbma0A4wjUwtYqGAXhDe/Qso75QLgUe2oW7UYA+95uYnbHTZthKy9UhvBwZ X-Received: by 2002:a17:90a:fa82:b0:296:37f0:ef3e with SMTP id cu2-20020a17090afa8200b0029637f0ef3emr1557062pjb.41.1706870337531; Fri, 02 Feb 2024 02:38:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706870337; cv=pass; d=google.com; s=arc-20160816; b=hwbrpGszHgBULQAAG6XCGl5KbIp0/0OFb+Xs+8aq2En24QglS6jARnKt933/70N+jG HFcPNbVgXhbsMAFUopTFbPxOpuUIDpifG8xVlAq9NmArWGwNJ/P3qQte+3oDc0oCkdQV GsOG9iet7jwCWajfQiOMPuiBAV8bOvIOTz8xfeq8781m9/vXS+DlgYhE10TIAzVSec4U eDKb5jKv+4jAKT1Ec7FYQrurMPNLGfwn3IiV6An7LOapSmutpCPi9Nffv7KqK6bNzKgR bU/oE5JS+z8LkC0Ol6yeDu5ffWBsktVaUctU5bL8vFJlXLdw6zV4ZQIUC3AD2381hLbZ f01Q== 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=CvYpZGtwgQAcALlwY/rcghvn9/62MbBnlRGTWh40zWI=; b=f56TD7UgYusL0vvqJsG/pUTXhqIxRwuRKcwjVEFWZoKcjv8J3+ZBiZd8JSR9mPrr8E 1KW2VhcA/gvFtj4rTOyLqSc/jrZ3S6jer8N3jTdwAi8UBLfbpbTCGgbRA+xucLPwQL3U mzZpubAIwrHKK60fpsFpPON6TYaQGdBSMrTT6MlVqwL53AQfv7KKK7+u/+Ps4wefogag SJrGU/eL50qkGgWa5favszwHfVqz7PMTHi0LmD/YughwOC8lI/nSTXulF6oLTQjeZHeT qsHdxfRfjW8T0zO7tAKt5nkOmElYqA+1r4ZIcW3tdljtCvh2HJIF4U/hrO0jNo02So3E y/3w==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49682-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUQ8Fym6tEI9YObnGmfqxZkVm/Hwpmgb9V9lRKy0rv3AbGnauT1PXXlwnWAi4Sh4KB0/JO3dhh87Du89stEDJuvAp0Q+YF2tSZeD5Wq1g== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id em8-20020a17090b014800b0029619c22c8bsi1471986pjb.112.2024.02.02.02.38.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 02:38:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49682-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49682-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2AA01290B07 for ; Fri, 2 Feb 2024 10:38:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 294DF13BEBA; Fri, 2 Feb 2024 10:38:50 +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 To: 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 , Sohil Mehta , Yonghong Song , 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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAn+REwxrxl46r1Cg--.15879S4 X-Coremail-Antispam: 1UD129KBjvJXoWxGF4xZrykXrW8KrWfGry3Arb_yoW5Gr4kpa 1kA343Gr4fKFyayr43G34DZayrJwn5tF17Wrn3Wr1rua17XFyFyrW0ga1Yqr9xAF9xK34Y vr1ftFykC3Wjq3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I 0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IY c2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s 026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF 0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0x vE42xK8VAvwI8IcIk0rVWrZr1j6s0DMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2 jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07UZ18PUUUUU= X-CM-SenderInfo: xkrx3t3r6k3tpzhluzxrxghudrp/ From: Hou Tao 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 -- 2.29.2