From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751718AbdIUK5R (ORCPT ); Thu, 21 Sep 2017 06:57:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49919 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751587AbdIUK5P (ORCPT ); Thu, 21 Sep 2017 06:57:15 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A259D2F9451 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=oleg@redhat.com Date: Thu, 21 Sep 2017 12:57:13 +0200 From: Oleg Nesterov To: Kees Cook Cc: Chris Salls , Andy Lutomirski , Will Drewry , "security@kernel.org" , LKML , Tycho Andersen Subject: Re: [PATCH] seccomp: fix the usage of get/put_seccomp_filter() in seccomp_get_filter() Message-ID: <20170921105713.GA32672@redhat.com> References: <20170920125621.GA3599@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 21 Sep 2017 10:57:15 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > (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. Oleg.