Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp399115imn; Wed, 3 Aug 2022 08:34:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Bt2zFxIOFKmLcZdW/qy/GuumoB+1h26tnQmDtZg72ocj7kcdS7ITu3WxZNKRAMX1UWW+2 X-Received: by 2002:a05:6402:4301:b0:43e:4d31:6ec0 with SMTP id m1-20020a056402430100b0043e4d316ec0mr2867172edc.69.1659540867345; Wed, 03 Aug 2022 08:34:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659540867; cv=none; d=google.com; s=arc-20160816; b=CPxNvXE37EKmm62/Auiq1qhdJ5tlI5I5XZ1HS9qPW9n5bQCRgulpJkIcWHHfpNDebP Bnr8aR8iv0vY9MguPi585qfEsm65JfynxNsklSfRJB2/Xq68itNRyNZnc1x/lREFAoQR mEUffO7LRz9iuCb33Unmp1qRyfAWw2jLihJaQF4LR1sdcQfCAhQQPhGCdbrq5x9mRx5G ZfmhSa2YWloQQV6R8R4/wIR+Sv4ctPXqtZS2V8P/Y3Xvbn0lLzwSLPpSMOZNXvc0cYIB FgG+fphIRzu39fhQT3hNOVXQqxv9JQiNnNXgXaveDsUj5S7QLLo3SengcbQLZRCkeAJA b6fQ== 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-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=NstIhUvDndfhWQhjJY54RegUN1YZlKiUPmz8PG5jen0=; b=MAJ2ezYIJH2j7sZpwzYvzQWsIEQCaG6Ejdw8VU4O1uWiFDu10hnOJxa2LLAT1G3Q3g 3NFZ7Xeb0SnSUYUlO9wjXh34GWTPDZGrwkYNuFdXAuAxF7JYRiTRGoe84KK/Dkj72jaS fz1g4qReAYr1CL9yrZ3/sLy1x9RqwgBPf6PW1hpZh/Ohjrz32lBqK0PXZae/YULk8s+K ir/SJiZLP2SfCi3/Zkq3Vr4WmvepoVkIs+q1RR2kFI/KTE4azgb1NBRN8RoNfMpgAC+T a6sp9NogH/o5xpeixUtgU5DVwpUNSXLWX/Zf1PrNtuYNbdq1SFS11IgU/mr1TYXH4Ygk bCFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kbUTCYf8; 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 d39-20020a056402402700b0043d451e9dcfsi11625926eda.339.2022.08.03.08.34.02; Wed, 03 Aug 2022 08:34:27 -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=kbUTCYf8; 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 S236201AbiHCP1Z (ORCPT + 99 others); Wed, 3 Aug 2022 11:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbiHCP1Y (ORCPT ); Wed, 3 Aug 2022 11:27:24 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D5211658B; Wed, 3 Aug 2022 08:27:23 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id a89so21932188edf.5; Wed, 03 Aug 2022 08:27:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc; bh=NstIhUvDndfhWQhjJY54RegUN1YZlKiUPmz8PG5jen0=; b=kbUTCYf8W9wxbL8ZzhcpD7tffIrDNB7uTgsF2jrAZFtiH+/oSbwNJ/59q6xBEJMGW5 J3+Df/AJ1ckT1I2e92XqpTGaXS6Cd9em/LvZQCXHq6f7fhkMGIWbyPCI6oEzx9Hvu3Pv wjv7zFVW5UrS4uZtf8ARoixOmHUNRriP/9I7fJ8GMQFZrYESpmtz2o93ThkCuW6iGey1 pAd+d48rHt6aNNq1H3yPQvdXUOyxSpCh4LKrA1wk1vok3txU+BKqUC0V92iqewwTQOtZ t3sO+fNKrrLbURpfaz5bhhn4diPvgIRrI7dIn8C69gYPh0CGplwCVPPGRsLQaNa16pss Q3xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc; bh=NstIhUvDndfhWQhjJY54RegUN1YZlKiUPmz8PG5jen0=; b=HVbillenALsdSzjVlD3Vfy+i8MVLYbCt29sWITwvNO+H/QdKtTOBovHWnhIczvauWz 0XyqsyFDeCwF2mupe/hlGglalfTkqkAMPsRV6M6/9s54dumKDUFHiBhFr5RfO85Iu4YS I2lcg7msl1rNQ3lX8dHdGNo9YokyOE/zoOYNlAg18g59jytAK9uhZR5xvWWpvFawoPS6 gA1nsH7D2OYo3oIharMmR6xBk7GC0PM4FBEU23SbBx67WN3++9QUamDQ3wOBKB1VJlS1 Dn4IjpM8NoxNvrqjsw9M/gKydCtkz1zM1rQLl/FQ9tHzSygga8hSau5IJMXr3YQemGvp T9LQ== X-Gm-Message-State: ACgBeo0RH5l+2LeuhLNrlHB1MQF4CaIbfmnQDJDnUdp5BQ5gO8OrvkCU Vhm/HewO6cu6vJ6dhWIHX8o= X-Received: by 2002:a05:6402:3583:b0:43d:6943:44a with SMTP id y3-20020a056402358300b0043d6943044amr18876184edc.409.1659540441529; Wed, 03 Aug 2022 08:27:21 -0700 (PDT) Received: from krava ([83.240.61.12]) by smtp.gmail.com with ESMTPSA id s10-20020aa7c54a000000b0043d1eff72b3sm8280323edr.74.2022.08.03.08.27.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Aug 2022 08:27:21 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Wed, 3 Aug 2022 17:27:19 +0200 To: Lee Jones 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 , bpf@vger.kernel.org Subject: Re: [PATCH v2 1/1] bpf: Drop unprotected find_vpid() in favour of find_get_pid() Message-ID: References: <20220803134821.425334-1-lee@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220803134821.425334-1-lee@kernel.org> 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 Wed, Aug 03, 2022 at 02:48:21PM +0100, Lee Jones wrote: > The documentation for find_pid() clearly states: nit: typo find_vpid > > "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 Acked-by: Jiri Olsa jirka > --- > > 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 >