Received: from smtp5-g21.free.fr (smtp5-g21.free.fr [212.27.42.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E31C37E7 for ; Wed, 31 Aug 2022 09:25:36 +0000 (UTC) Received: from mail.thom.fr.eu.org (unknown [IPv6:2a01:e0a:2aa:1dd0::2]) by smtp5-g21.free.fr (Postfix) with ESMTPS id DC10E60155; Wed, 31 Aug 2022 11:25:33 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.thom.fr.eu.org (8.15.2/8.15.2/Debian-22) with ESMTP id 27V9PXFP204922; Wed, 31 Aug 2022 11:25:33 +0200 From: =?utf-8?q?Fran=C3=A7ois_Legal?= In-Reply-To: Content-Type: text/plain; charset="utf-8" X-Forward: 217.109.173.233, 165.225.20.103 Date: Wed, 31 Aug 2022 11:25:33 +0200 Cc: "Jan Kiszka" , xenomai@lists.linux.dev Precedence: bulk X-Mailing-List: xenomai@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: Subject: =?utf-8?q?Re=3A?= Using setuid to relinquish root rights User-Agent: SOGoMail 5.0.1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: clamav-milter 0.103.6 at tls-srv-03 X-Virus-Status: Clean Le Mercredi, Ao=C3=BBt 31, 2022 11:11 CEST, Fran=C3=A7ois Legal a =C3=A9crit: > Le Mardi, Ao=C3=BBt 09, 2022 07:56 CEST, Jan Kiszka a =C3=A9crit: > > > On 05.08.22 14:50, Fran=C3=A7ois Legal wrote: > > > Hello, > > > > > > I'm running a Xenomai (3.1) app, that comprises both realtime xen= omai thread and plain linux threads. The app starts as root so as to be= able to bind <1024 tcp sockets. > > > > > > After initialisation of the sockets and RT IPCs, I would like to = reliquinsh root rights, by calling setuid. > > > > > > After that call, I get lots of syscall <56> denied to "One of my= RT thread" and syscall <61> denied to "One of my RT thread". > > > > > > I figured out I had to set the CAP=5FSYS=5FNICE capability to the= app before, so I added > > > caps =3D cap=5Fget=5Fproc(); > > > cap=5Fset=5Fflag(caps, CAP=5FEFFECTIVE, 1, cap=5Flist, CAP=5FSET)= ; > > > cap=5Fset=5Fproc(caps); > > > prctl(PR=5FSET=5FKEEPCAPS, 1, 0, 0, 0); > > > > > > Without success. Morevover, the user that I set the uid to has gr= oup xenomai as primary group plus I do echo 1000 > /sys/module/xenomai= /parameters/allowed=5Fgroup before running the app, but still. > > > > > > Anybody can point me in the right direction. > > > > > > > We may have regressions here as this configuration is not systemati= cally > > tested. From your description and me read-up of our current logic, = this > > is supposed to work fine. > > > > Can you debug the kernel logic in more details, check, if the cap i= s > > raised properly during the xenomai bind syscall and if we are later= on > > checking it correctly? Maybe some other condition that the cap if > > failing, though I don't see yet which one. > > > > Jan > > > > I could take some time to see what happens. I probably had a problem = in my capability setting code. > For reference, this is my understanding of what has to be done : > > Set the KEEPCAPS security bit > Relinquish root rights > Set the CAP=5FSYS=5FNICE capability > > After this sequence, the CAP=5FSYS=5FNICE is correctly set in the pro= cess (you can tell by checking CapEff in /proc/[pid]/status) > > However, I seem to have a chicken and egg problem here. > > Reliquinshing of root rights is done after IPCs and thread creation, = so my thread are running. The problem is that as soon as setuid is call= ed, then every thread using IPCs start running round as the call to IPC= functions return error, and it seem the main thread never get to be sc= heduled to set the CAP=5FSYS=5FNICE bit. > > If I try to relinquish root rights after my IPCs are created but befo= re the threads are created, I get an error while creating the threads. > If I try to raise the main thread priority before doing the sequence,= it does not work (pthread=5Fsetschedparam=5Fex returns 20) > > Does all this means I have to do the root rights relinquish sequence = in the thread with the highest priority ? > I just tried that too, and it does not work either. The other thread se= em to be running round on failing IPC (semaphore in my test case) calls= . > Thanks > > Fran=C3=A7ois > > > -- > > Siemens AG, Technology > > Competence Center Embedded Linux > >