netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Carlos Antonio Neira Bustos <cneirabustos@gmail.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"ebiederm@xmission.com" <ebiederm@xmission.com>,
	"brouer@redhat.com" <brouer@redhat.com>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next V9 1/3] bpf: new helper to obtain namespace data from current task
Date: Tue, 20 Aug 2019 17:29:54 +0000	[thread overview]
Message-ID: <e1265647-f934-1cb5-a31d-73608b7adad5@fb.com> (raw)
In-Reply-To: <20190820151040.GA53610@localhost>



On 8/20/19 8:10 AM, Carlos Antonio Neira Bustos wrote:
> Hi Yonghong,
> 
> Thanks for taking the time to review this.
> 
> 
>>> + *
>>> + *		**-EINVAL** if *size_of_pidns* is not valid or unable to get ns, pid
>>> + *		or tgid of the current task.
>>> + *
>>> + *		**-ECHILD** if /proc/self/ns/pid does not exists.
>>> + *
>>> + *		**-ENOTDIR** if /proc/self/ns does not exists.
>>
>> Let us remove ECHILD and ENOTDIR and replace it with ENOENT as I
>> described below.
>>
>> Please *do verify* what happens when namespaces or pid_ns are not
>> configured.
>>
> 
> 
> I have tested kernel configurations without namespace support and with
> namespace support but without pid namespaces, the helper returns -EINVAL
> on both cases, now it should return -ENOENT.

Indeed. -ENOENT is better.

> 
> 
>>> +struct bpf_pidns_info {
>>> +	__u32 dev;
>>
>> Please add a comment for dev for how device major and minor number are
>> derived. User space gets device major and minor number, they need to
>> compare to the corresponding major/minor numbers returned by this helper.
>>
>>> +	__u32 nsid;
>>> +	__u32 tgid;
>>> +	__u32 pid;
>>> +};
>>
> 
> What do you think of this comment ?
> 
> struct bpf_pidns_info {
> 	__u32 dev;	/* major/minor numbers from /proc/self/ns/pid.
> 			 * User space gets device major and minor numbers from
> 			 * the same device that need to be compared against the
> 			 * major/minor numbers returned by this helper.
> 			 */
> 	__u32 nsid;
> 	__u32 tgid;
> 	__u32 pid;
> };
> 

To be more specific, I like a comment similar to below in uapi bpf.h

struct bpf_cgroup_dev_ctx {
         /* access_type encoded as (BPF_DEVCG_ACC_* << 16) | 
BPF_DEVCG_DEV_* */
         __u32 access_type;
         __u32 major;
         __u32 minor;
};

Some like:
	/* dev encoded as (major << 8 | (minor & 0xff)) */

>>
>> Please put an empty line. As a general rule for readability,
>> put an empty line if control flow is interrupted, e.g., by
>> "return", "break" or "continue". At least this is what
>> I saw most in bpf mailing list.
>>
> I'll fix it in version 10.
> 
>>> +	len = strlen(pidns_path) + 1;
>>> +	memcpy((char *)tmp->name, pidns_path, len);
>>> +	tmp->uptr = NULL;
>>> +	tmp->aname = NULL;
>>> +	tmp->refcnt = 1;
>>> +	ret = filename_lookup(AT_FDCWD, tmp, 0, &kp, NULL);
>> Adding below to free kmem cache memory
>> 	kmem_cache_free(names_cachep, fname);
>>
> 
> I think we don't need to call kmem_cache_free as filename_lookup
> calls putname that calls kmem_cache_free.

Oh, right. Thanks for checking this.

> 
> 
> Thanks a lot for your help.
> 
> Bests
> 
>> In the above, we checked task_active_pid_ns().
>> If not returning NULL, we have a valid pid ns. So the above
>> filename_lookup should not go wrong. We can still keep
>> the error checking though.
>>
>>> +	if (ret) {
>>> +		memset((void *)pidns_info, 0, (size_t) size);
>>> +		return ret;
>>
>>
> 
> I think we could get rid of this.
> 
> 

  reply	other threads:[~2019-08-20 17:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-13 18:47 [PATCH bpf-next V9 0/3] BPF: New helper to obtain namespace data from current task Carlos Neira
2019-08-13 18:47 ` [PATCH bpf-next V9 1/3] bpf: new " Carlos Neira
2019-08-13 22:35   ` Yonghong Song
2019-08-20 15:10     ` Carlos Antonio Neira Bustos
2019-08-20 17:29       ` Yonghong Song [this message]
2019-08-13 23:11   ` Yonghong Song
2019-08-13 23:51     ` [Potential Spoof] " Yonghong Song
2019-08-14  0:56     ` Carlos Antonio Neira Bustos
2019-08-14  4:50       ` Yonghong Song
     [not found]         ` <CACiB22jyN9=0ATWWE+x=BoWD6u+8KO+MvBfsFQmcNfkmANb2_w@mail.gmail.com>
2019-08-28 20:39           ` Carlos Antonio Neira Bustos
2019-08-28 20:53             ` Yonghong Song
2019-08-28 21:03               ` Carlos Antonio Neira Bustos
2019-09-03 18:45                 ` Carlos Antonio Neira Bustos
2019-09-03 20:36                   ` Yonghong Song
2019-08-13 18:47 ` [PATCH bpf-next V9 2/3] samples/bpf: added sample code for bpf_get_current_pidns_info Carlos Neira
2019-08-13 18:47 ` [PATCH bpf-next V9 3/3] tools/testing/selftests/bpf: Add self-tests for new helper Carlos Neira
2019-08-13 23:19   ` Yonghong Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e1265647-f934-1cb5-a31d-73608b7adad5@fb.com \
    --to=yhs@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=cneirabustos@gmail.com \
    --cc=ebiederm@xmission.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).