Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751884AbdIUTvm (ORCPT ); Thu, 21 Sep 2017 15:51:42 -0400 Received: from mail-io0-f177.google.com ([209.85.223.177]:50417 "EHLO mail-io0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751754AbdIUTvl (ORCPT ); Thu, 21 Sep 2017 15:51:41 -0400 X-Google-Smtp-Source: AOwi7QA/MioyFBjsxqeT+BKWUs4yknG14w2Y/FVfB1vqYzUu0N6LjWcRQaWt09ftCu1meLxd61Geczm+WgQrbUbpQt4= MIME-Version: 1.0 In-Reply-To: <20170921105713.GA32672@redhat.com> References: <20170920125621.GA3599@redhat.com> <20170921105713.GA32672@redhat.com> From: Kees Cook Date: Thu, 21 Sep 2017 12:51:40 -0700 X-Google-Sender-Auth: LZX2OCpCsg51XHPsOIpSK5pGyRE Message-ID: Subject: Re: [PATCH] seccomp: fix the usage of get/put_seccomp_filter() in seccomp_get_filter() To: Oleg Nesterov Cc: Chris Salls , Andy Lutomirski , Will Drewry , "security@kernel.org" , LKML , Tycho Andersen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1365 Lines: 45 On Thu, Sep 21, 2017 at 3:57 AM, Oleg Nesterov wrote: > On 09/20, Kees Cook wrote: >> >> On Wed, Sep 20, 2017 at 5:56 AM, Oleg Nesterov wrote: >> > @@ -908,13 +912,13 @@ long seccomp_get_filter(struct task_struct *task, unsigned long filter_off, >> > if (!data) >> > goto out; >> > >> > - get_seccomp_filter(task); >> > + refcount_inc(&filter->usage); >> > spin_unlock_irq(&task->sighand->siglock); >> > >> > if (copy_to_user(data, fprog->filter, bpf_classic_proglen(fprog))) >> > ret = -EFAULT; >> > >> > - put_seccomp_filter(task); >> > + __put_seccomp_filter(filter); >> > return ret; >> >> Given how reference counting is done for filters, I'd be happier with >> leaving the get_seccomp_filter() as-is, > > No, please note that filter != tsk->seccomp.filter, get_seccomp_filter() > won't work. Ah yes, sorry, you're right. >> (i.e. don't open-code >> the refcount_inc()). > > agreed, probably another __get_seccomp_filter(filter) makes sense, especially > if we do other changes like get_nth(). > > But imo not in this fix. Regardless, whatever lands will need backport adjustment for refcount_*/atomic_* in -stable. Can you resend the two patches; I can send the backport to -stable manually... -Kees -- Kees Cook Pixel Security