Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp553160rdb; Fri, 26 Jan 2024 04:02:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGu4Cg0Gtqal55OYNsOsquBJJuednoTOCxdcKtDT2j0An8ZKjqNzjySLjQhQffKMmhCS/sy X-Received: by 2002:a05:6a20:6709:b0:199:d648:7d87 with SMTP id q9-20020a056a20670900b00199d6487d87mr1256054pzh.81.1706270573372; Fri, 26 Jan 2024 04:02:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706270573; cv=pass; d=google.com; s=arc-20160816; b=D2aO4Nu9wahQ5DAEBDcGIoDxUu02hHRHXT4lGwX1SL8GibUnajiNiR1T4ems+l9c2e a16nvg39otdYGThUZz6GJIFG9+W5FWTy4S6Y++Eq8YyO5IzVYcUreRNtmz4IlwJ/zudB HyqGyUcv3H3ZRl8d5rGkUo0cbzCR5W4Z2eZvpLXwBgH2NeQOm+E2qHU65zSLENNbDez9 WrGaTTUzJUx/qFxKobt1aN3JEqBdkaATDGt9Nbb9ZM6M+UD0THQMNdLb1JliY6ur2daX zsJoMPNDzWuBNJ0kMvCWn2qtz3jNLtGytGriMWCfIiNcMdZYzcrCcKh+B6LELvZfgKWq 0aMQ== 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=D6C49tRlpQwH038UesnNMSwFKqYwl3EtQ/2RPKmh6og=; fh=G+80uKrcZQu3HF50WBlLamYOf34JlQTSQytwkjSpE8g=; b=M5afqMdt29ojRdq6oXREmlNPoQFnc9PCCGWhR828qx8H0wwGA8ond5NZ0uXuEODyzj TXX1wkWbT6I32QOYqEuqUSWxxN2X8vjpfFva8Yu24+fMjZ8uhZltpZm5OtzjdvzPK4XP 1Qo38pZPKsXc8+fkK11EgYtXqNBCJLtGH0eQOeXEFZKhFmdtRi8a0hn9bjLswO2OKpIM 6huKcy00QfMaYDYQnPvRNP8cJCbuNoPa9/bSxnelaj3CW/humHwkf/P7mBipJ0/8ARNT XIScS8+3hH1WTB5oZ8cHVOb13hQleBsRo9pwFzHeVMVnFxi9d5sCq4mErslIefBYKhRJ t+8A== 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-40070-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40070-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y123-20020a633281000000b005cfbd17c5efsi1005567pgy.672.2024.01.26.04.02.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 04:02:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40070-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-40070-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40070-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 A6ED5299CC4 for ; Fri, 26 Jan 2024 11:54:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE93C19470; Fri, 26 Jan 2024 11:54:01 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (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 8C5521B942; Fri, 26 Jan 2024 11:53:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706270041; cv=none; b=qiA+AjB95WKqqN5DbgKPJ0IOhmLCWfb+IkNqHUMMXPsJ00afitB18PaP11UwXLY3hFwcuOgZTlOGYF2R+XeXmWpr//5llLnUDC8Jjbg/+5b2gJldUhoflG685c6jGx1M9gM7hO/sDJvpCNLcqz22NGiqX+0BEVKhUj3S5c4i3ys= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706270041; c=relaxed/simple; bh=R4KIdldmuAPxvE+dKo2d3Bmt5lX4dAInQbxjdGrFa6E=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ZU6dfsN7Q8xFgaG/1YvxJ/vTK8LkXGq3ITZPKXYf9ONjFq5T4/6wfdWZmpx8CY4KNyoHpwN8vQAvMKb7IRGpXJo+gCi/gLBxhEBu4VFtCLKos3arqsMJFI6vCHA4iiHWrq+RAgobESFPmDnNH9/G9RnC3l+5bLueoDlZMjhJGQE= 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.51 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 dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TLx1D2kqXz4f3jqC; Fri, 26 Jan 2024 19:53:52 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id C374E1A0232; Fri, 26 Jan 2024 19:53:54 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP1 (Coremail) with SMTP id cCh0CgBHZQ42nbNllmgoCA--.1892S4; Fri, 26 Jan 2024 19:53:53 +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 v2 0/3] Fix the read of vsyscall page through bpf Date: Fri, 26 Jan 2024 19:54:20 +0800 Message-Id: <20240126115423.3943360-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:cCh0CgBHZQ42nbNllmgoCA--.1892S4 X-Coremail-Antispam: 1UD129KBjvJXoWxJr4rKrWUGF13trWkAr43Wrg_yoW8tFWDpa y8A343Kr4rKFy3Ar43W3srZayrAwn5tF47Wrn7Wr1rZ3y7XFyFvryIga4Yqr9xAF9xKryY vr4ftFykG3Wjqa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7Cj 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: v2: * 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 | 9 +++ .../selftests/bpf/prog_tests/read_vsyscall.c | 57 +++++++++++++++++++ .../selftests/bpf/progs/read_vsyscall.c | 45 +++++++++++++++ 5 files changed, 121 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