From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753209AbbIKO7U (ORCPT ); Fri, 11 Sep 2015 10:59:20 -0400 Received: from mail-ig0-f176.google.com ([209.85.213.176]:38676 "EHLO mail-ig0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751749AbbIKO7S (ORCPT ); Fri, 11 Sep 2015 10:59:18 -0400 Date: Fri, 11 Sep 2015 08:59:16 -0600 From: Tycho Andersen To: Alexei Starovoitov Cc: Kees Cook , Alexei Starovoitov , "David S. Miller" , Will Drewry , Oleg Nesterov , Andy Lutomirski , Pavel Emelyanov , "Serge E. Hallyn" , Daniel Borkmann , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-api@vger.kernel.org Subject: Re: [PATCH v2 3/5] ebpf: add a way to dump an eBPF program Message-ID: <20150911145916.GK27574@smitten> References: <1441930862-14347-1-git-send-email-tycho.andersen@canonical.com> <1441930862-14347-4-git-send-email-tycho.andersen@canonical.com> <20150911022940.GA4903@Alexeis-MacBook-Pro-2.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150911022940.GA4903@Alexeis-MacBook-Pro-2.local> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 10, 2015 at 07:29:42PM -0700, Alexei Starovoitov wrote: > On Thu, Sep 10, 2015 at 06:21:00PM -0600, Tycho Andersen wrote: > > +static int bpf_prog_dump(union bpf_attr *attr, union bpf_attr __user *uattr) > > +{ > > + int ufd = attr->prog_fd; > > + struct fd f = fdget(ufd); > > + struct bpf_prog *prog; > > + int ret = -EINVAL; > > + > > + prog = get_prog(f); > > + if (IS_ERR(prog)) > > + return PTR_ERR(prog); > > + > > + /* For now, let's refuse to dump anything that isn't a seccomp program. > > + * Other program types have support for maps, which our current dump > > + * code doesn't support. > > + */ > > + if (prog->type != BPF_PROG_TYPE_SECCOMP) > > + goto out; > > + > > + ret = -EFAULT; > > + if (put_user(prog->len, &uattr->dump_insn_cnt)) > > + goto out; > > + > > + if (put_user((u8) prog->gpl_compatible, &uattr->gpl_compatible)) > > + goto out; > > + > > + if (attr->dump_insns) { > > + u32 len = prog->len * sizeof(struct bpf_insn); > > + > > + if (copy_to_user(u64_to_ptr(attr->dump_insns), > > + prog->insns, len) != 0) > > + goto out; > > + } > > + > > + ret = 0; > > +out: > > + return ret; > > fdput() is missing in all error paths. So it is, thanks! Tycho