Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp519682imi; Thu, 21 Jul 2022 05:59:57 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uhG3q0RzkI/PenB19ht9utoCTluQ3VhnteV3VsROn+M1jCaz4LJsb6rZMEFJB7wMFVoXqL X-Received: by 2002:a05:6a00:4148:b0:52b:603c:d3a with SMTP id bv8-20020a056a00414800b0052b603c0d3amr24973131pfb.3.1658408397479; Thu, 21 Jul 2022 05:59:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658408397; cv=none; d=google.com; s=arc-20160816; b=pdiYUT0y0J2OYSGa3SMUPeCIj7wQslqzW4SDjGdmQv6In5Vjdbtmj4whC+43ZbhtnN RGzzzIVaFRodhvoCKOqNhWwIoIamnaBIrH/otA66lmEaK907SE8aJQ8SBJX1kn6/aFfK LFIGC8lKVwi6cIPG8aPS3Ge4O+AU19g2VgQFUv3cUXMj6tCoYVzIz2xzs57Qi6t8tiuj nG9/XRpNXkakOSjdJpX4m/oFeI98r1dpNvYPE/O7H22tg1fza6RYsHH57130GiI96Lbn rWF/Vsrm9qOpHhzuUjDzWc4Y2wWknwmY4RWuJYf/nUcVpChb+LdTEdo6yz9v+J1ut8Ei YfEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=VSbWBr2PqZxxIcgEaWX5b/CKC10J1bxUMK1hG4Jb/vc=; b=KqyHiJiJ5o7YViNuo5W+Lf373uNJkHUYFMJNS5czkFC6Mcfo/JqbqNo/nRJQlE8/xI otPvTNlQiE/kWRFzFi259io27HG9vHhz6Bk4txXpOI2BQe+GDmzETGwCgNx3sNS9siPE m9L6RkwWTNP10gC0u40grNdg8y3RZO52w9OXBZvhVivSlo2Hjb0vpmJtpse18ITHi5MZ lX54mAaZDzWqrWXNscTAQqAACSEuo7e53Oo/djWLzgI1YNA6R0fDDyD4WxZ60GJm7r+i WhRh8oBvGh/qckbTAOzs58pJ/ADkaZ6JTbQdyIqaC+x1WKM5GFkux8/6/aGJmML+rS1P Ffkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=NGpJOVfw; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q11-20020a170902dacb00b0016be773edb6si2572436plx.32.2022.07.21.05.59.43; Thu, 21 Jul 2022 05:59:57 -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=@gmail.com header.s=20210112 header.b=NGpJOVfw; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233244AbiGUMPB (ORCPT + 99 others); Thu, 21 Jul 2022 08:15:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiGUMO7 (ORCPT ); Thu, 21 Jul 2022 08:14:59 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79CEA863F4; Thu, 21 Jul 2022 05:14:58 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id m8so1887068edd.9; Thu, 21 Jul 2022 05:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=VSbWBr2PqZxxIcgEaWX5b/CKC10J1bxUMK1hG4Jb/vc=; b=NGpJOVfwssqjngg2xYTFLZrZBj/N8tDxK1KV8Ddk6vAjmjQBTwUtLzC+UgGiY9WO9X XccwZUffn8Vf53j0La4f05uzhgM7UBJ+/bV0tu5F6tAt4iegfs+2PAppV1fxV9lBfbyn vuPi56tV/3xg5tVp1u6Ch2TqX8ErgBvHAJEaJPrnZ4qnvveI4TC5REiAoJDqUwWXK6U4 HBuavEfhc2b75fQ57IKbg9hrJUxb5RR5pshno53klRULSV1RTirbyuCBYpSCpURHqEll Od3eaFXHdHBn5PTQr5R4m10GdOd+8B3V7ZbqLY5+K0KFyRsaLG4EXSIer0EDig0UfGst zJmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=VSbWBr2PqZxxIcgEaWX5b/CKC10J1bxUMK1hG4Jb/vc=; b=j7HwctSvlT0exgr414DhF1NmI/KvNSRfPextccJ1To/ck1Wkt9sVhRJ9YSSWiShplw ZlHMpjfA9be7G7ivIYOz6KHlK3gmyWRKLxHAoQqg8UcQqyPr0xi0mWtnw0ABcHi7WuBH bi8pWnRJnqMUtzFQ+lTsmiDKdGRf9DoaIZH7AqshtCa53ARGnV6IKOTe1QDteGzTJswJ N7ucNtaTJaeCaitrDUGAvZRd88BQCV0zngOyXei9fo7lDoUQO3CGR4lHHVKr6gLMg8e9 JMh87nmCx+PG5ZWsmoqaezgUM1XiPbj3hZGpyeXzNGrp14YW3hneSx1XvVMqJjqVFvGL RRGw== X-Gm-Message-State: AJIora8+IQioW4Lfnr50jQ8BS2CWlnQcBeZLXa9LUW0nMqAECqn0cnXh KD3JEhxrTQV6RAaTFVwXuvc= X-Received: by 2002:a05:6402:518b:b0:43a:dc65:35f8 with SMTP id q11-20020a056402518b00b0043adc6535f8mr57668291edd.185.1658405697000; Thu, 21 Jul 2022 05:14:57 -0700 (PDT) Received: from krava ([193.85.244.190]) by smtp.gmail.com with ESMTPSA id kw26-20020a170907771a00b0072124df085bsm817249ejc.15.2022.07.21.05.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 05:14:56 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Thu, 21 Jul 2022 14:14:53 +0200 To: Lee Jones Cc: Jiri Olsa , 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 , bpf@vger.kernel.org Subject: Re: [PATCH 1/1] bpf: Drop unprotected find_vpid() in favour of find_get_pid() Message-ID: References: <20220721111430.416305-1-lee@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 On Thu, Jul 21, 2022 at 12:59:09PM +0100, Lee Jones wrote: > On Thu, 21 Jul 2022, Jiri Olsa wrote: > > > On Thu, Jul 21, 2022 at 12:14:30PM +0100, Lee Jones wrote: > > > The documentation for find_pid() clearly states: typo find_vpid > > > > > > "Must be called with the tasklist_lock or rcu_read_lock() held." > > > > > > Presently we do neither. just curious, did you see crash related to this or you just spot that > > > > > > In an ideal world we would wrap the in-lined call to find_vpid() along > > > with get_pid_task() in the suggested rcu_read_lock() and have done. > > > However, looking at get_pid_task()'s internals, it already does that > > > independently, so this would lead to deadlock. > > > > hm, we can have nested rcu_read_lock calls, right? > > I assumed not, but that might be an oversight on my part. > > Would that be your preference? seems simpler than calling get/put for ppid jirka > > > > Instead, we'll 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 > > > --- > > > 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; > > > > > -- > Lee Jones [李琼斯]