From owner-svn-src-head@freebsd.org Wed Mar 13 19:14:56 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E5924153E996; Wed, 13 Mar 2019 19:14:55 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1B15E6B00D; Wed, 13 Mar 2019 19:14:54 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id x2DJElDs004443 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 13 Mar 2019 21:14:50 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua x2DJElDs004443 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id x2DJElfT004442; Wed, 13 Mar 2019 21:14:47 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 13 Mar 2019 21:14:47 +0200 From: Konstantin Belousov To: Hans Petter Selasky Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r345100 - head/sys/compat/linuxkpi/common/include/linux Message-ID: <20190313191447.GC2492@kib.kiev.ua> References: <201903131855.x2DItg7s091824@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201903131855.x2DItg7s091824@repo.freebsd.org> User-Agent: Mutt/1.11.3 (2019-02-01) X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on tom.home X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Mar 2019 19:14:56 -0000 On Wed, Mar 13, 2019 at 06:55:42PM +0000, Hans Petter Selasky wrote: > Author: hselasky > Date: Wed Mar 13 18:55:41 2019 > New Revision: 345100 > URL: https://svnweb.freebsd.org/changeset/base/345100 > > Log: > Implement task_euid() and get_task_state() function macros in the LinuxKPI. > > Submitted by: Johannes Lundberg > MFC after: 1 week > Sponsored by: Limelight Networks > Sponsored by: Mellanox Technologies > > Modified: > head/sys/compat/linuxkpi/common/include/linux/sched.h > > Modified: head/sys/compat/linuxkpi/common/include/linux/sched.h > ============================================================================== > --- head/sys/compat/linuxkpi/common/include/linux/sched.h Wed Mar 13 18:53:29 2019 (r345099) > +++ head/sys/compat/linuxkpi/common/include/linux/sched.h Wed Mar 13 18:55:41 2019 (r345100) > @@ -95,7 +95,9 @@ struct task_struct { > #define get_pid(x) (x) > #define put_pid(x) do { } while (0) > #define current_euid() (curthread->td_ucred->cr_uid) > +#define task_euid(task) ((task)->task_thread->td_ucred->cr_uid) This looks very strange if you compare the definition of task_euid() with the definition of linux_task_exiting() in r345098. There you access td_ucred which is basically volatile and invalid unless the thread is known to be inhibited or sleeping (and not exiting). So to use the macro safely for task not associated with current thread, you must have very strong and unusual external guarantees. On the other hand, linux_task_exiting() correctly locks the target process. But, since the lock is dropped before the function returns, the process might exit wheh the callers gets to use the result. Again, some external guarantees must be ensured to give safe use for this macro as well, for the target process != curproc. > > +#define get_task_state(task) atomic_read(&(task)->state) > #define set_task_state(task, x) atomic_set(&(task)->state, (x)) > #define __set_task_state(task, x) ((task)->state.counter = (x)) > #define set_current_state(x) set_task_state(current, x)