public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Xi Wang <xi.wang@gmail.com>
Cc: Daniel Borkmann <dborkman@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Russell King <linux@arm.linux.org.uk>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	Eric Dumazet <edumazet@google.com>,
	Will Drewry <wad@chromium.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH net-next 2/6] x86: bpf_jit_comp: support BPF_S_ANC_SECCOMP_LD_W instruction
Date: Fri, 26 Apr 2013 08:11:34 -0700	[thread overview]
Message-ID: <1366989094.8964.212.camel@edumazet-glaptop> (raw)
In-Reply-To: <CAKU6vyZfYR-2408G0_Fkp-PS5x5rMH+s4_OOWqqi7Nt+UfiUPg@mail.gmail.com>

On Fri, 2013-04-26 at 10:50 -0400, Xi Wang wrote:
> On Fri, Apr 26, 2013 at 10:18 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> > On Fri, 2013-04-26 at 03:51 -0400, Xi Wang wrote:
> >
> >> +#ifdef CONFIG_SECCOMP_FILTER
> >> +                     case BPF_S_ANC_SECCOMP_LD_W:
> >> +                             if (K == offsetof(struct seccomp_data, arch)) {
> >> +                                     int arch = syscall_get_arch(current, NULL);
> >> +
> >> +                                     EMIT1_off32(0xb8, arch); /* mov arch,%eax */
> >> +                                     break;
> >> +                             }
> >> +                             func = (u8 *)seccomp_bpf_load;
> >> +                             t_offset = func - (image + addrs[i]);
> >> +                             EMIT1_off32(0xbf, K); /* mov imm32,%edi */
> >> +                             EMIT1_off32(0xe8, t_offset); /* call seccomp_bpf_load */
> >> +                             break;
> >> +#endif
> >
> > This seems seriously wrong to me.
> 
> Can you elaborate?
> 
> > This cannot have been tested at all.
> 
> Thanks to QEMU for hiding bugs then. :)



1) 'current' at the time the code is jitted (compiled) is not the
'current' at the time the filter will be evaluated.

On x86_64, if CONFIG_IA32_EMULATION=y, syscall_get_arch() evaluates to :

if (task_thread_info(task)->status & TS_COMPAT)
	return AUDIT_ARCH_I386;
return AUDIT_ARCH_X86_64;

So your code is completely wrong.

2) Calling a function potentially destroys some registers.
   %rdi,%r8,%r9 for instance, so we are going to crash very easily.

I dont know, I feel a bit uncomfortable having to explain this to
someone sending security related patches...

  reply	other threads:[~2013-04-26 15:11 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-26  7:51 [RFC PATCH net-next 0/6] seccomp filter JIT Xi Wang
2013-04-26  7:51 ` [RFC PATCH net-next 1/6] filter: refactor BPF JIT for seccomp filters Xi Wang
2013-04-26 15:20   ` Eric Dumazet
2013-04-26  7:51 ` [RFC PATCH net-next 2/6] x86: bpf_jit_comp: support BPF_S_ANC_SECCOMP_LD_W instruction Xi Wang
2013-04-26 14:18   ` Eric Dumazet
2013-04-26 14:50     ` Xi Wang
2013-04-26 15:11       ` Eric Dumazet [this message]
2013-04-26 15:29         ` Xi Wang
2013-04-26 15:43           ` Eric Dumazet
2013-04-26 15:57             ` Xi Wang
2013-04-26 18:48             ` David Miller
2013-04-26 16:02         ` Xi Wang
2013-04-26 16:14           ` Eric Dumazet
2013-04-26 18:25             ` Xi Wang
2013-04-26 18:40               ` Eric Dumazet
2013-04-26 15:15       ` David Laight
2013-04-26 15:27         ` Eric Dumazet
2013-04-26 15:38           ` David Laight
2013-04-26 15:46             ` Eric Dumazet
2013-04-26  7:51 ` [RFC PATCH net-next 3/6] ARM: net: bpf_jit_32: " Xi Wang
2013-04-26  7:51 ` [RFC PATCH net-next 4/6] PPC: net: bpf_jit_comp: refactor the BPF JIT interface Xi Wang
2013-04-26  7:51 ` [RFC PATCH net-next 5/6] sparc: " Xi Wang
2013-04-26  7:51 ` [RFC PATCH net-next 6/6] s390/bpf,jit: " Xi Wang
2013-04-26 11:25 ` [RFC PATCH net-next 0/6] seccomp filter JIT Heiko Carstens
2013-04-26 11:46   ` Heiko Carstens
2013-04-26 12:15     ` Xi Wang
2013-04-26 11:46   ` Daniel Borkmann
2013-04-26 12:31     ` Xi Wang
2013-04-26 12:38       ` Daniel Borkmann
2013-04-29 12:18       ` Nicolas Schichan
2013-04-29 13:21         ` Nicolas Schichan

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=1366989094.8964.212.camel@edumazet-glaptop \
    --to=eric.dumazet@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=dborkman@redhat.com \
    --cc=edumazet@google.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=wad@chromium.org \
    --cc=xi.wang@gmail.com \
    /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