From patchwork Wed Apr 24 22:33:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 2486781 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork2.kernel.org (Postfix) with ESMTP id 23144DF25A for ; Wed, 24 Apr 2013 22:33:40 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UV8Fp-0006V0-Mz; Wed, 24 Apr 2013 22:33:33 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UV8Fn-0004XU-35; Wed, 24 Apr 2013 22:33:31 +0000 Received: from mail.linuxfoundation.org ([140.211.169.12]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UV8Fj-0004Ws-GO for linux-arm-kernel@lists.infradead.org; Wed, 24 Apr 2013 22:33:28 +0000 Received: from akpm3.mtv.corp.google.com (unknown [216.239.45.95]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 77C51894; Wed, 24 Apr 2013 22:33:24 +0000 (UTC) Date: Wed, 24 Apr 2013 15:33:23 -0700 From: Andrew Morton To: Nicolas Schichan Subject: Re: [PATCH V2 1/3] seccomp: add generic code for jitted seccomp filters. Message-Id: <20130424153323.73901c8e026580dc279329b0@linux-foundation.org> In-Reply-To: <5177FFC2.5020102@freebox.fr> References: <1363618233-6375-1-git-send-email-nschichan@freebox.fr> <1363618233-6375-2-git-send-email-nschichan@freebox.fr> <20130417145628.88058f0f3104ab9ae551ddd3@linux-foundation.org> <51752D98.8070709@freebox.fr> <20130423164303.d2eb663c4a1becea4a185087@linux-foundation.org> <5177FFC2.5020102@freebox.fr> X-Mailer: Sylpheed 3.2.0beta5 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130424_183327_706508_9B6AC397 X-CRM114-Status: GOOD ( 17.61 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Serge Hallyn , Will Drewry , Kees Cook , linux-kernel@vger.kernel.org, Eric Paris , Mircea Gherzan , Al Viro , James Morris , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org On Wed, 24 Apr 2013 17:52:34 +0200 Nicolas Schichan wrote: > > btw, what on earth is going on with seccomp_jit_free()? It does > > disturbing undocumented typecasting and it punts the module_free into a > > kernel thread for mysterious, undocumented and possibly buggy reasons. > > > > I realize it just copies bpf_jit_free(). The same observations apply there. > > The reason for this hack for both seccomp filters and socket filters is that > {seccomp,bpf}_jit_free are called from a softirq. module_free() cannot be > called directly from softirq, as it will in turn call vfree() which will > BUG_ON() if in_interrupt() is non zero. So to call module_free(), it is > therefore required to be in a process context, which is provided by the work > struct. Well let's explain this to the next sucker who comes along. From: Andrew Morton Subject: bpf: add comments explaining the schedule_work() operation Cc: Will Drewry Cc: Mircea Gherzan Cc: Nicolas Schichan Cc: Russell King Cc: "David S. Miller" Cc: Daniel Borkmann Signed-off-by: Andrew Morton --- arch/arm/net/bpf_jit_32.c | 8 ++++++++ arch/powerpc/net/bpf_jit_comp.c | 4 ++++ arch/s390/net/bpf_jit_comp.c | 4 ++++ arch/sparc/net/bpf_jit_comp.c | 4 ++++ arch/x86/net/bpf_jit_comp.c | 4 ++++ 5 files changed, 24 insertions(+) diff -puN include/linux/filter.h~a include/linux/filter.h diff -puN net/core/filter.c~a net/core/filter.c diff -puN arch/arm/net/bpf_jit_32.c~a arch/arm/net/bpf_jit_32.c --- a/arch/arm/net/bpf_jit_32.c~a +++ a/arch/arm/net/bpf_jit_32.c @@ -958,6 +958,10 @@ void bpf_jit_free(struct sk_filter *fp) struct work_struct *work; if (fp->bpf_func != sk_run_filter) { + /* + * bpf_jit_free() can be called from softirq; module_free() + * requires process context. + */ work = (struct work_struct *)fp->bpf_func; INIT_WORK(work, bpf_jit_free_worker); @@ -985,6 +989,10 @@ void seccomp_jit_free(struct seccomp_fil void *bpf_func = seccomp_filter_get_bpf_func(fp); if (bpf_func != sk_run_filter) { + /* + * seccomp_jit_free() can be called from softirq; module_free() + * requires process context. + */ work = (struct work_struct *)bpf_func; INIT_WORK(work, bpf_jit_free_worker); diff -puN arch/sparc/net/bpf_jit_comp.c~a arch/sparc/net/bpf_jit_comp.c --- a/arch/sparc/net/bpf_jit_comp.c~a +++ a/arch/sparc/net/bpf_jit_comp.c @@ -817,6 +817,10 @@ static void jit_free_defer(struct work_s void bpf_jit_free(struct sk_filter *fp) { if (fp->bpf_func != sk_run_filter) { + /* + * bpf_jit_free() can be called from softirq; module_free() + * requires process context. + */ struct work_struct *work = (struct work_struct *)fp->bpf_func; INIT_WORK(work, jit_free_defer); diff -puN arch/powerpc/net/bpf_jit_comp.c~a arch/powerpc/net/bpf_jit_comp.c --- a/arch/powerpc/net/bpf_jit_comp.c~a +++ a/arch/powerpc/net/bpf_jit_comp.c @@ -699,6 +699,10 @@ static void jit_free_defer(struct work_s void bpf_jit_free(struct sk_filter *fp) { if (fp->bpf_func != sk_run_filter) { + /* + * bpf_jit_free() can be called from softirq; module_free() + * requires process context. + */ struct work_struct *work = (struct work_struct *)fp->bpf_func; INIT_WORK(work, jit_free_defer); diff -puN arch/s390/net/bpf_jit_comp.c~a arch/s390/net/bpf_jit_comp.c --- a/arch/s390/net/bpf_jit_comp.c~a +++ a/arch/s390/net/bpf_jit_comp.c @@ -818,6 +818,10 @@ void bpf_jit_free(struct sk_filter *fp) if (fp->bpf_func == sk_run_filter) return; + /* + * bpf_jit_free() can be called from softirq; module_free() requires + * process context. + */ work = (struct work_struct *)fp->bpf_func; INIT_WORK(work, jit_free_defer); schedule_work(work); diff -puN arch/x86/net/bpf_jit_comp.c~a arch/x86/net/bpf_jit_comp.c --- a/arch/x86/net/bpf_jit_comp.c~a +++ a/arch/x86/net/bpf_jit_comp.c @@ -749,6 +749,10 @@ static void jit_free_defer(struct work_s void bpf_jit_free(struct sk_filter *fp) { if (fp->bpf_func != sk_run_filter) { + /* + * bpf_jit_free() can be called from softirq; module_free() + * requires process context. + */ struct work_struct *work = (struct work_struct *)fp->bpf_func; INIT_WORK(work, jit_free_defer);