mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net: sock: correctly handle failed prog retrieval from fd
@ 2014-12-12  5:33 Sasha Levin
  2014-12-12  6:34 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Sasha Levin @ 2014-12-12  5:33 UTC (permalink / raw)
  To: davem; +Cc: ast, dborkman, hannes, netdev, linux-kernel, Sasha Levin

Commit "net: sock: allow eBPF programs to be attached to sockets" didn't
correctly handle the case where there is a failure getting the prog from
a given fd.

This allows for easy NULL ptr deref from userspace.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
 net/core/filter.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/core/filter.c b/net/core/filter.c
index 8cc3c03..ec9baea 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -1103,8 +1103,8 @@ int sk_attach_bpf(u32 ufd, struct sock *sk)
 		return -EPERM;
 
 	prog = bpf_prog_get(ufd);
-	if (!prog)
-		return -EINVAL;
+	if (IS_ERR(prog))
+		return PTR_ERR(prog);
 
 	if (prog->aux->prog_type != BPF_PROG_TYPE_SOCKET_FILTER) {
 		/* valid fd, but invalid program type */
-- 
2.1.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] net: sock: correctly handle failed prog retrieval from fd
  2014-12-12  5:33 [PATCH] net: sock: correctly handle failed prog retrieval from fd Sasha Levin
@ 2014-12-12  6:34 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2014-12-12  6:34 UTC (permalink / raw)
  To: Sasha Levin
  Cc: David S. Miller, Daniel Borkmann, Hannes Frederic Sowa,
	Network Development, LKML

On Thu, Dec 11, 2014 at 9:33 PM, Sasha Levin <sasha.levin@oracle.com> wrote:
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 8cc3c03..ec9baea 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -1103,8 +1103,8 @@ int sk_attach_bpf(u32 ufd, struct sock *sk)
>                 return -EPERM;
>
>         prog = bpf_prog_get(ufd);
> -       if (!prog)
> -               return -EINVAL;
> +       if (IS_ERR(prog))
> +               return PTR_ERR(prog);

thank you for the fix, but the same fix is already applied
to net-next and pushed all the way to:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=198bf1b046e370a7d3987b195cff5f1efebec3ac
sorry for the headache that this bug caused.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-12-12  6:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-12  5:33 [PATCH] net: sock: correctly handle failed prog retrieval from fd Sasha Levin
2014-12-12  6:34 ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®