Subject: Re: [PATCH net-next 4/6] kcm: Kernel Connection Multiplexor module

From: Daniel Borkmann <[email-masked]>
Date: Mon, 23 Nov 2015 10:42:10 +0100

On 11/20/2015 10:21 PM, Tom Herbert wrote:
[...]
> +
> +/* Macro to invoke filter function. */
> +#define KCM_RUN_FILTER(prog, ctx) \
> +	(*prog->bpf_func)(ctx, prog->insnsi)

Any reason to redefine this macro?

We already have the same one as:

#define BPF_PROG_RUN(filter, ctx)  (*filter->bpf_func)(ctx, filter->insnsi)

[...]
> +static int kcm_attach_ioctl(struct socket *sock, struct kcm_attach *info)
> +{
> +	struct socket *csock;
> +	struct bpf_prog *prog;
> +	int err;
> +
> +	csock = sockfd_lookup(info->fd, &err);
> +	if (!csock)
> +		return -ENOENT;
> +
> +	prog = bpf_prog_get(info->bpf_fd);
> +	if (IS_ERR(prog)) {
> +		err = PTR_ERR(prog);
> +		goto out;
> +	}
> +
> +	if (prog->type != BPF_PROG_TYPE_SOCKET_FILTER) {
> +		bpf_prog_put(prog);

I'd move this and the below bpf_prog_put() under out_put label, too.

> +		err = -EINVAL;
> +		goto out;
> +	}
> +
> +	err = kcm_attach(sock, csock, prog);
> +	if (err) {
> +		bpf_prog_put(prog);

                 ^^^

> +		goto out;
> +	}
> +
> +	/* Keep reference on file also */
> +
> +	return 0;
> +out:
> +	fput(csock->file);
> +	return err;
> +}
[...]