Message ID | a1a9810494aebf0c0be8660e996b84c1cdb06444.1423610452.git.daniel@iogearbox.net |
---|---|
State | RFC, archived |
Delegated to: | David Miller |
Headers | show |
On Tue, Feb 10, 2015 at 4:15 PM, Daniel Borkmann <daniel@iogearbox.net> wrote: > Just minor ... before doing all the copying work, we may want > to check for instruction count earlier. Also, we may want to > warn the user in case we would otherwise need to truncate the > license information. > > Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> > --- > kernel/bpf/syscall.c | 17 +++++++++-------- > 1 file changed, 9 insertions(+), 8 deletions(-) > > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c > index 536edc2..73b105c 100644 > --- a/kernel/bpf/syscall.c > +++ b/kernel/bpf/syscall.c > @@ -473,25 +473,26 @@ static int bpf_prog_load(union bpf_attr *attr) > { > enum bpf_prog_type type = attr->prog_type; > struct bpf_prog *prog; > - int err; > char license[128]; > bool is_gpl; > + int err; > > if (CHECK_ATTR(BPF_PROG_LOAD)) > return -EINVAL; > + if (attr->insn_cnt >= BPF_MAXINSNS) > + return -EINVAL; > > /* copy eBPF program license from user space */ > - if (strncpy_from_user(license, u64_to_ptr(attr->license), > - sizeof(license) - 1) < 0) > - return -EFAULT; > - license[sizeof(license) - 1] = 0; > + err = strncpy_from_user(license, u64_to_ptr(attr->license), > + sizeof(license)); > + if (err == sizeof(license)) > + err = -ERANGE; I think this error is misleading. In case of license we care whether it's gpl or not. This boolean indicator we remember for the life of the program. We don't keep the license. So if user specified 'my_ultra_long_proprietery_license' that should be fine. The program should still be accepted and marked as non-gpl. > + if (err < 0) > + return err; > > /* eBPF programs must be GPL compatible to use GPL-ed functions */ > is_gpl = license_is_gpl_compatible(license); > > - if (attr->insn_cnt >= BPF_MAXINSNS) > - return -EINVAL; moving this check, I guess, is fine. No one should depend on order of errors. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 02/11/2015 02:21 AM, Alexei Starovoitov wrote: ... > So if user specified 'my_ultra_long_proprietery_license' > that should be fine. The program should still be accepted > and marked as non-gpl. Yep, true. Most likely I'll drop this one for non-RFC anyway as it's not much of value. ;) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 536edc2..73b105c 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -473,25 +473,26 @@ static int bpf_prog_load(union bpf_attr *attr) { enum bpf_prog_type type = attr->prog_type; struct bpf_prog *prog; - int err; char license[128]; bool is_gpl; + int err; if (CHECK_ATTR(BPF_PROG_LOAD)) return -EINVAL; + if (attr->insn_cnt >= BPF_MAXINSNS) + return -EINVAL; /* copy eBPF program license from user space */ - if (strncpy_from_user(license, u64_to_ptr(attr->license), - sizeof(license) - 1) < 0) - return -EFAULT; - license[sizeof(license) - 1] = 0; + err = strncpy_from_user(license, u64_to_ptr(attr->license), + sizeof(license)); + if (err == sizeof(license)) + err = -ERANGE; + if (err < 0) + return err; /* eBPF programs must be GPL compatible to use GPL-ed functions */ is_gpl = license_is_gpl_compatible(license); - if (attr->insn_cnt >= BPF_MAXINSNS) - return -EINVAL; - /* plain bpf_prog allocation */ prog = bpf_prog_alloc(bpf_prog_size(attr->insn_cnt), GFP_USER); if (!prog)
Just minor ... before doing all the copying work, we may want to check for instruction count earlier. Also, we may want to warn the user in case we would otherwise need to truncate the license information. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> --- kernel/bpf/syscall.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)