Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp373049imn; Wed, 3 Aug 2022 07:31:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR4yK0fMcSksovpLAt850GqLVMLWM9OT8IbHDDShD9671fYM7bklfP8PzyBlaI0MDs8z5+b7 X-Received: by 2002:a17:902:6b4b:b0:16e:ef21:5664 with SMTP id g11-20020a1709026b4b00b0016eef215664mr14039913plt.122.1659537067496; Wed, 03 Aug 2022 07:31:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659537067; cv=none; d=google.com; s=arc-20160816; b=Sjb/BgM5JcAFH133nw9l5Jp4K3JA+KvoDbYu0RiWjYKZHIMqvgM4cKuYAzP+QwLbJb OEJBZ2avq7DNvGUv6WV7oR2NOGtDCkJphhVKH69Dp+hxrpuh03Ql7iz7OJ4i2vGjFVwb mOcISfmAd8i2ntmY5aNE0z3w6Y0DYDZngxZstV4q62QueHoY36KP9u5W4Lx4CVI/46c8 WJvaOTSIxEUgJr/roE7zIrEd0XvARNOFzM6RV8230ea6BpVjMOaS42Z4tBJ9jcagU0tX 6nwIhXICwAOYIjgV2qHqV2rZ6FSltfhQOsG8BxngvhXDFfLJf/8azFW3YI/7u/JydHbB aoiw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=aH/ZJEgLApQRZkUn4AC4+ooFTY5Ab1VqKoUi6G5qBag=; b=BwqUzmZ0lXTPX828GzLbUnqqKtWg5sWo7XOOy2St56s2KXU3dDuh3uPhYbsdlc2XC1 qI1uv0P7mkVjpF7rS6RpIq7R35xemCu0rd26HZHj7Xnw/l0LCe2LP1J6fxwt2iFLTIHN IeUmmH4P07RZvHwQBGenZXlFOc9CS0575rZK3eeJT1It3uHR19bETIb2HDmyIuBwPjnz aFai1yBCXZm+w6AbWo/CMaKtPApzH6kwMpDj/oeG7HFqy0y5RLosTfOR1q+D+yW7RTr+ ed4pgjw0HOTLCflXvhPqjfAvUahRZXFKDpx89OledoeMfkGPeGhRyCpJOxj8ddLq/bbh t7Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ETuvR63h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cj6-20020a056a00298600b0052dccbf4079si5933485pfb.220.2022.08.03.07.30.46; Wed, 03 Aug 2022 07:31:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ETuvR63h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S238718AbiHCNvt (ORCPT + 99 others); Wed, 3 Aug 2022 09:51:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238721AbiHCNvW (ORCPT ); Wed, 3 Aug 2022 09:51:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 639B9459B8; Wed, 3 Aug 2022 06:48:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A6B20B822AF; Wed, 3 Aug 2022 13:48:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF834C433D7; Wed, 3 Aug 2022 13:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659534519; bh=QofVbPFWlQ6HFFbhEFcRVeQJ036YZ+JLjvZNFuTDFtg=; h=From:To:Cc:Subject:Date:From; b=ETuvR63hPfNyjnl8aA1zTfgeCrhaMDHj/D46IrW4izDOlIEB7pd84ceNLjR9ThUW9 Sa/qTouElugysbtT5O1rw5NfPBpYmvl5C/NJVkDeuJp8xAkTn0MPPqNktJBYviyC+v nIoVV65WE6PWw/RqdA0YLqX/s5TLT6gV3cD9wp652TK/Tdp0mkEJ0qDIXpWB1XusSI xfgjkFWY25hPpVKMfi+U7VTtn9bHZHRM7VwbjEzW8Xx6S9xiZ7hRF8SyygttIApiCN 7QjVd1/EmkwzeNFyooyt2ZcYWo8D6dtLr4zkv+oh1MTt6x+P0a4gObrs0DERzGUleJ OwAQSHDnMlxcw== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org Subject: [PATCH v2 1/1] bpf: Drop unprotected find_vpid() in favour of find_get_pid() Date: Wed, 3 Aug 2022 14:48:21 +0100 Message-Id: <20220803134821.425334-1-lee@kernel.org> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The documentation for find_pid() clearly states: "Must be called with the tasklist_lock or rcu_read_lock() held." Presently we do neither. Let's use find_get_pid() which searches for the vpid, then takes a reference to it preventing early free, all within the safety of rcu_read_lock(). Once we have our reference we can safely make use of it up until the point it is put. Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: John Fastabend Cc: Andrii Nakryiko Cc: Martin KaFai Lau Cc: Song Liu Cc: Yonghong Song Cc: KP Singh Cc: Stanislav Fomichev Cc: Hao Luo Cc: Jiri Olsa Cc: bpf@vger.kernel.org Fixes: 41bdc4b40ed6f ("bpf: introduce bpf subcommand BPF_TASK_FD_QUERY") Signed-off-by: Lee Jones --- v1 => v2: * Commit log update - no code differences kernel/bpf/syscall.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 83c7136c5788d..c20cff30581c4 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -4385,6 +4385,7 @@ static int bpf_task_fd_query(const union bpf_attr *attr, const struct perf_event *event; struct task_struct *task; struct file *file; + struct pid *ppid; int err; if (CHECK_ATTR(BPF_TASK_FD_QUERY)) @@ -4396,7 +4397,9 @@ static int bpf_task_fd_query(const union bpf_attr *attr, if (attr->task_fd_query.flags != 0) return -EINVAL; - task = get_pid_task(find_vpid(pid), PIDTYPE_PID); + ppid = find_get_pid(pid); + task = get_pid_task(ppid, PIDTYPE_PID); + put_pid(ppid); if (!task) return -ENOENT; -- 2.37.1.455.g008518b4e5-goog