Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Engineering without management is art." -- Jeff Johnson


devel / comp.unix.programmer / Restricting who can run a set-user-id-root executable

SubjectAuthor
* Restricting who can run a set-user-id-root executableNoob
+* Re: Restricting who can run a set-user-id-root executableBen Bacarisse
|`* Re: Restricting who can run a set-user-id-root executableNoob
| `- Re: Restricting who can run a set-user-id-root executableRichard Kettlewell
+* Re: Restricting who can run a set-user-id-root executableKenny McCormack
|+- Re: Restricting who can run a set-user-id-root executableNoob
|`* Re: Restricting who can run a set-user-id-root executableJohn McCue
| `* Re: Restricting who can run a set-user-id-root executableNoob
|  `* Re: Restricting who can run a set-user-id-root executableJohn McCue
|   `* Re: Restricting who can run a set-user-id-root executableNoob
|    +- Re: Restricting who can run a set-user-id-root executableJohn McCue
|    `* Re: Restricting who can run a set-user-id-root executableKenny McCormack
|     `* Re: Restricting who can run a set-user-id-root executableRainer Weikusat
|      `* Re: Restricting who can run a set-user-id-root executableKenny McCormack
|       `* Re: Restricting who can run a set-user-id-root executableRainer Weikusat
|        `* Re: Restricting who can run a set-user-id-root executableKenny McCormack
|         `* Re: Restricting who can run a set-user-id-root executableRainer Weikusat
|          `* Re: Restricting who can run a set-user-id-root executableKenny McCormack
|           `* Re: Restricting who can run a set-user-id-root executableRainer Weikusat
|            `- Re: Restricting who can run a set-user-id-root executableKenny McCormack
+* Re: Restricting who can run a set-user-id-root executableJames K. Lowden
|+- Re: Restricting who can run a set-user-id-root executableKenny McCormack
|+* Re: Restricting who can run a set-user-id-root executableKeith Thompson
||`* Re: Restricting who can run a set-user-id-root executableNoob
|| `- Re: Restricting who can run a set-user-id-root executableKeith Thompson
|`* Re: Restricting who can run a set-user-id-root executableNoob
| `- Re: Restricting who can run a set-user-id-root executableJames K. Lowden
`* Re: Restricting who can run a set-user-id-root executableRainer Weikusat
 `* Re: Restricting who can run a set-user-id-root executableNoob
  `- Re: Restricting who can run a set-user-id-root executableRainer Weikusat

Pages:12
Restricting who can run a set-user-id-root executable

<sljmug$8di$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16722&group=comp.unix.programmer#16722

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: root@127.0.0.1 (Noob)
Newsgroups: comp.unix.programmer
Subject: Restricting who can run a set-user-id-root executable
Date: Sat, 30 Oct 2021 17:04:48 +0200
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <sljmug$8di$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 30 Oct 2021 15:04:48 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7f90123c57edd30b19c6984fdba19791";
logging-data="8626"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX186n/4IpFuU9g2H5tawNVlC9oZC2rdv5k0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:yjmOfP5Lf8eokTuECiJ5gMc3klk=
Content-Language: en-US
X-Mozilla-News-Host: snews://news.eternal-september.org:563
 by: Noob - Sat, 30 Oct 2021 15:04 UTC

Hello,

(It's been an exceedingly long time since I last posted here. Happy to be back)

I've written my first Linux set-user-id-root program (let's call it foo-bin)

foo-bin is suid-root because:
1) foo-bin is supposed to be run by an unprivileged user,
2) foo-bin makes privileged system calls (unshare, chroot, mount, setgroups)

I didn't want *every* unprivileged user to be able to run foo-bin.
Only user 12345 is allowed to run foo-bin.

So I just added trivial code at the start of foo-bin:

if (getuid() != 12345)
die("Bad credentials");

My understanding is that, for an executable with the suid-root bit set,
the process's effective-user-id and saved-user-id will be 0 (root) while the
real-user-id (returned by getuid) will be that of the user running the program.

Thus my two-line "fix" seemed (seems?) like a perfect solution...
Yet, I didn't find anyone suggesting it on the interwebz, so I figured
it's just too simple to be correct.

I know there are things like dynamic library preloading that might allow
one to change getuid() to a no-op. (Though I'm aware that Linux ignores
dynamic library preloading for suid-root, probably for that reason.)

Could you point out how/why the proposed solution breaks/falls apart?

There's a different approach that would also work:
1) put foo-bin in user12345's group (chown root:user12345 foo-bin)
2) allow group to run foo-bin, not others (chmod 4750 foo-bin)

Thus:
1) "random" normal users are not allowed to run foo-bin
2) user12345 is the only unprivileged user allowed to run foo-bin

Perhaps this solution is safer/better than my first solution?

Happy to read all your comments ;)

Regards.

Re: Restricting who can run a set-user-id-root executable

<87lf2athnh.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16723&group=comp.unix.programmer#16723

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sat, 30 Oct 2021 20:52:02 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <87lf2athnh.fsf@bsb.me.uk>
References: <sljmug$8di$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="bed14636410651230bd102096cdcac7d";
logging-data="28200"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18aixALMAvKr9p/g/CNHpavmRnEpQ2r0l0="
Cancel-Lock: sha1:bcM4qUJg7E0rJxd4i8iz9nsvr5Q=
sha1:ZGyulVtYHvxmAfgD08V1skxazn8=
X-BSB-Auth: 1.2a208207e18442e15b70.20211030205202BST.87lf2athnh.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 30 Oct 2021 19:52 UTC

Noob <root@127.0.0.1> writes:

> I've written my first Linux set-user-id-root program (let's call it foo-bin)
>
> foo-bin is suid-root because:
> 1) foo-bin is supposed to be run by an unprivileged user,
> 2) foo-bin makes privileged system calls (unshare, chroot, mount, setgroups)
>
> I didn't want *every* unprivileged user to be able to run foo-bin.
> Only user 12345 is allowed to run foo-bin.
>
> So I just added trivial code at the start of foo-bin:
>
> if (getuid() != 12345)
> die("Bad credentials");

Generally, this sort of thing is done using sudo rather than hard-wiring
UIDs into source code. That sets my (code) teeth on edge!

--
Ben.

Re: Restricting who can run a set-user-id-root executable

<slkael$8ac$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16724&group=comp.unix.programmer#16724

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sat, 30 Oct 2021 20:37:41 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <slkael$8ac$1@news.xmission.com>
References: <sljmug$8di$2@dont-email.me>
Injection-Date: Sat, 30 Oct 2021 20:37:41 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="8524"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sat, 30 Oct 2021 20:37 UTC

In article <sljmug$8di$2@dont-email.me>, Noob <root@127.0.0.1> wrote:
....
>There's a different approach that would also work:
>1) put foo-bin in user12345's group (chown root:user12345 foo-bin)
>2) allow group to run foo-bin, not others (chmod 4750 foo-bin)

My first (and best) thought was to do it via grops. Seems tailor-made for
this.

I'd create a new group (Say, foo-bin-users) and add your user to that
group. This makes it easy to add others in the future.

--
The single most important statistic in the US today - the one that explains all the
others - is this: 63 million people thought it was a good idea to vote for this clown
(and will probably do so again). Everything else is secondary to that. Everything else
could be fixed if we can revert this one statistic. Nothing can be fixed until we do.

Re: Restricting who can run a set-user-id-root executable

<20211030170846.ef437b362217cf4a4614936e@speakeasy.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16725&group=comp.unix.programmer#16725

  copy link   Newsgroups: comp.unix.programmer
Date: Sat, 30 Oct 2021 17:08:46 -0400
From: jklowden@speakeasy.net (James K. Lowden)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Message-Id: <20211030170846.ef437b362217cf4a4614936e@speakeasy.net>
References: <sljmug$8di$2@dont-email.me>
X-Newsreader: Sylpheed 3.4.3 (GTK+ 2.24.28; x86_64--netbsd)
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Lines: 11
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.usenet.farm!feed.usenet.farm!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!2a07:8080:119:fe::49.MISMATCH!news.newsdemon.com!not-for-mail
NNTP-Posting-Date: Sat, 30 Oct 2021 21:08:46 +0000
X-Received-Bytes: 719
Organization: NewsDemon - www.newsdemon.com
X-Complaints-To: abuse@newsdemon.com
 by: James K. Lowden - Sat, 30 Oct 2021 21:08 UTC

On Sat, 30 Oct 2021 17:04:48 +0200
Noob <root@127.0.0.1> wrote:

> 2) allow group to run foo-bin, not others (chmod 4750 foo-bin)

Don't you mean 4640? 0644 is typical for binaries. You're removing
world access and adding set-user-ID.

--jkl

Re: Restricting who can run a set-user-id-root executable

<slkcqf$a86$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16726&group=comp.unix.programmer#16726

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sat, 30 Oct 2021 21:18:07 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <slkcqf$a86$1@news.xmission.com>
References: <sljmug$8di$2@dont-email.me> <20211030170846.ef437b362217cf4a4614936e@speakeasy.net>
Injection-Date: Sat, 30 Oct 2021 21:18:07 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="10502"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sat, 30 Oct 2021 21:18 UTC

In article <20211030170846.ef437b362217cf4a4614936e@speakeasy.net>,
James K. Lowden <jklowden@speakeasy.net> wrote:
>On Sat, 30 Oct 2021 17:04:48 +0200
>Noob <root@127.0.0.1> wrote:
>
>> 2) allow group to run foo-bin, not others (chmod 4750 foo-bin)
>
>
>Don't you mean 4640? 0644 is typical for binaries. You're removing
>world access and adding set-user-ID.

No. 755 is normal for executable files. You could get away with 711.

Actually, a habit I got into lomg ago, which has served me well over the
years, is to do: chmod 4711 ...

whenever I want to make something setuid (root).

So, if you're going to do the "group thing", it would be 4710.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Seriously

Re: Restricting who can run a set-user-id-root executable

<874k8yyzt5.fsf@nosuchdomain.example.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16727&group=comp.unix.programmer#16727

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sat, 30 Oct 2021 14:20:54 -0700
Organization: None to speak of
Lines: 21
Message-ID: <874k8yyzt5.fsf@nosuchdomain.example.com>
References: <sljmug$8di$2@dont-email.me>
<20211030170846.ef437b362217cf4a4614936e@speakeasy.net>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="679ddad86518bcd07b55dfd2beeff025";
logging-data="4457"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18g91b+x3tGyDFpXBjRIl94"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:6vcP3z8vRhp4wlg3xr0VV1g5b94=
sha1:qJghq4wffmYNc2Izk1p2iVsyFiQ=
 by: Keith Thompson - Sat, 30 Oct 2021 21:20 UTC

"James K. Lowden" <jklowden@speakeasy.net> writes:
> On Sat, 30 Oct 2021 17:04:48 +0200
> Noob <root@127.0.0.1> wrote:
>
>> 2) allow group to run foo-bin, not others (chmod 4750 foo-bin)
>
>
> Don't you mean 4640? 0644 is typical for binaries. You're removing
> world access and adding set-user-ID.

Hmm? 4640 means no execute permission for anyone.

And since the original requirement was to allow only one *user*
to execute it, I'm not sure why everyone is talking about group
permissions. I'd make it 4700 or 4500 and set its ownership to
the one user who's allowed to execute it.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Restricting who can run a set-user-id-root executable

<slke9h$fbv$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16728&group=comp.unix.programmer#16728

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: root@127.0.0.1 (Noob)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sat, 30 Oct 2021 23:43:12 +0200
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <slke9h$fbv$1@dont-email.me>
References: <sljmug$8di$2@dont-email.me>
<20211030170846.ef437b362217cf4a4614936e@speakeasy.net>
<874k8yyzt5.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 30 Oct 2021 21:43:13 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7f90123c57edd30b19c6984fdba19791";
logging-data="15743"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18l+Q8I5S1TFlvU9oHlHCk/od5KHLUG0vc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:2QnrVwAPKD9i4MOmv29b5WKbmb4=
In-Reply-To: <874k8yyzt5.fsf@nosuchdomain.example.com>
Content-Language: en-US
 by: Noob - Sat, 30 Oct 2021 21:43 UTC

On 30/10/2021 23:20, Keith Thompson wrote:

> "James K. Lowden" writes:
>>
>> Noob wrote:
>>
>>> 2) allow group to run foo-bin, not others (chmod 4750 foo-bin)
>>
>> Don't you mean 4640? 0644 is typical for binaries. You're removing
>> world access and adding set-user-ID.
>
> Hmm? 4640 means no execute permission for anyone.
>
> And since the original requirement was to allow only one *user*
> to execute it, I'm not sure why everyone is talking about group
> permissions. I'd make it 4700 or 4500 and set its ownership to
> the one user who's allowed to execute it.

Original requirement was to allow only one user to execute foo-bin *as root*

Therefore, foo-bin must be owned by root :)

Regards.

Re: Restricting who can run a set-user-id-root executable

<slkegv$gr1$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16729&group=comp.unix.programmer#16729

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: root@127.0.0.1 (Noob)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sat, 30 Oct 2021 23:47:10 +0200
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <slkegv$gr1$1@dont-email.me>
References: <sljmug$8di$2@dont-email.me> <slkael$8ac$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 30 Oct 2021 21:47:11 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7f90123c57edd30b19c6984fdba19791";
logging-data="17249"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zOuG0/MvWdJl8MJXJuOcIcPDlsiTcIAE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:JD2uMvL9BZ/Pqb8S0gmyu3PI0Ro=
In-Reply-To: <slkael$8ac$1@news.xmission.com>
Content-Language: en-US
 by: Noob - Sat, 30 Oct 2021 21:47 UTC

On 30/10/2021 22:37, Kenny McCormack wrote:

> In article <sljmug$8di$2@dont-email.me>, Noob wrote:
> ...
>> There's a different approach that would also work:
>> 1) put foo-bin in user12345's group (chown root:user12345 foo-bin)
>> 2) allow group to run foo-bin, not others (chmod 4750 foo-bin)
>
> My first (and best) thought was to do it via grops. Seems tailor-made for
> this.

s/grops/groups ? (I first parsed that as "grope", then gr_ops)

If groups, then you are agreeing with me, right?

> I'd create a new group (Say, foo-bin-users) and add your user to that
> group. This makes it easy to add others in the future.

I understand your point.

Regards.

Re: Restricting who can run a set-user-id-root executable

<slkep1$ibf$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16730&group=comp.unix.programmer#16730

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: root@127.0.0.1 (Noob)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sat, 30 Oct 2021 23:51:28 +0200
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <slkep1$ibf$1@dont-email.me>
References: <sljmug$8di$2@dont-email.me>
<20211030170846.ef437b362217cf4a4614936e@speakeasy.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 30 Oct 2021 21:51:29 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7f90123c57edd30b19c6984fdba19791";
logging-data="18799"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/rPASbTlSqLIpQUOv1CzsxQL65ZudAhE0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:gzoYzCyGfSauZfUjz7lLQ8H0MZw=
In-Reply-To: <20211030170846.ef437b362217cf4a4614936e@speakeasy.net>
Content-Language: en-US
 by: Noob - Sat, 30 Oct 2021 21:51 UTC

On 30/10/2021 23:08, James K. Lowden wrote:

> Noob wrote:
>
>> 2) allow group to run foo-bin, not others (chmod 4750 foo-bin)
>
> Don't you mean 4640? 0644 is typical for binaries. You're removing
> world access and adding set-user-ID.

Your suggestion must be a typo/thinko?

Execute bit is 1. So none of 6,4,0 have the execute bit set.
Which is a problem for an executable :)

Regards.

Re: Restricting who can run a set-user-id-root executable

<slkk4u$l5m$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16731&group=comp.unix.programmer#16731

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jmccue@fuzzball.mhome.org (John McCue)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sat, 30 Oct 2021 23:23:10 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <slkk4u$l5m$1@dont-email.me>
References: <sljmug$8di$2@dont-email.me> <slkael$8ac$1@news.xmission.com>
Reply-To: jmclnx@SPAMisBADgmail.com
Injection-Date: Sat, 30 Oct 2021 23:23:10 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="01978964c4c47aeeaf6e6bea2dd3fae0";
logging-data="21686"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UQ2l/rRFWjz39oYlwc70d"
User-Agent: tin/2.4.4-20191224 ("Millburn") (OpenBSD/7.0 (amd64))
Cancel-Lock: sha1:fb7EyvLfaPzulH2076acXTunbkU=
X-OS-Version: OpenBSD 7.0 amd64
 by: John McCue - Sat, 30 Oct 2021 23:23 UTC

Kenny McCormack <gazelle@shell.xmission.com> wrote:
> In article <sljmug$8di$2@dont-email.me>, Noob <root@127.0.0.1> wrote:
> ...
>>There's a different approach that would also work:
>>1) put foo-bin in user12345's group (chown root:user12345 foo-bin)
>>2) allow group to run foo-bin, not others (chmod 4750 foo-bin)
>
> My first (and best) thought was to do it via grops. Seems tailor-made for
> this.
>
> I'd create a new group (Say, foo-bin-users) and add your user to that
> group. This makes it easy to add others in the future.

That was what I thought too, then I realized may be better
to not bother with getuid(2) getgid(2) and just do:

# chgrp foo-bin
# chmod 750 foo-bin

Then it is not tied to a specific hard-coded ID/Group
and no setgid needed

--
csh(1) - "An elegant shell, for a more... civilized age."
- Paraphrasing Star Wars

Re: Restricting who can run a set-user-id-root executable

<20211030210740.0ee5e794f0a9848c9cefdc4e@speakeasy.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16732&group=comp.unix.programmer#16732

  copy link   Newsgroups: comp.unix.programmer
Date: Sat, 30 Oct 2021 21:07:40 -0400
From: jklowden@speakeasy.net (James K. Lowden)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Message-Id: <20211030210740.0ee5e794f0a9848c9cefdc4e@speakeasy.net>
References: <sljmug$8di$2@dont-email.me> <20211030170846.ef437b362217cf4a4614936e@speakeasy.net> <slkep1$ibf$1@dont-email.me>
X-Newsreader: Sylpheed 3.4.3 (GTK+ 2.24.28; x86_64--netbsd)
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Lines: 12
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!tr2.eu1.usenetexpress.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!2a07:8080:119:fe:2ddf:7d15:5c99:67fa.MISMATCH!news.newsdemon.com!not-for-mail
NNTP-Posting-Date: Sun, 31 Oct 2021 01:07:40 +0000
X-Received-Bytes: 859
X-Complaints-To: abuse@newsdemon.com
Organization: NewsDemon - www.newsdemon.com
 by: James K. Lowden - Sun, 31 Oct 2021 01:07 UTC

On Sat, 30 Oct 2021 23:51:28 +0200
Noob <root@127.0.0.1> wrote:

> > Don't you mean 4640? 0644 is typical for binaries. You're removing
> > world access and adding set-user-ID.
>
> Your suggestion must be a typo/thinko?

Yah. More coffee and less scotch, I guess. Or the opposite.

--jkl

Re: Restricting who can run a set-user-id-root executable

<87zgqpy9j3.fsf@nosuchdomain.example.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16733&group=comp.unix.programmer#16733

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sat, 30 Oct 2021 23:48:32 -0700
Organization: None to speak of
Lines: 26
Message-ID: <87zgqpy9j3.fsf@nosuchdomain.example.com>
References: <sljmug$8di$2@dont-email.me>
<20211030170846.ef437b362217cf4a4614936e@speakeasy.net>
<874k8yyzt5.fsf@nosuchdomain.example.com> <slke9h$fbv$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="6c1dc95e53090ff41220db7d966572eb";
logging-data="31466"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+h8AnCxoOxf1c+j4Ql0DdZ"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:K8T6WGnOvbf0i2RFAiTRaQcxgTw=
sha1:jup6jbPKKZpBK7u6f1/0q92KA2s=
 by: Keith Thompson - Sun, 31 Oct 2021 06:48 UTC

Noob <root@127.0.0.1> writes:
> On 30/10/2021 23:20, Keith Thompson wrote:
>> "James K. Lowden" writes:
>>> Noob wrote:
>>>> 2) allow group to run foo-bin, not others (chmod 4750 foo-bin)
>>>
>>> Don't you mean 4640? 0644 is typical for binaries. You're removing
>>> world access and adding set-user-ID.
>>
>> Hmm? 4640 means no execute permission for anyone.
>>
>> And since the original requirement was to allow only one *user*
>> to execute it, I'm not sure why everyone is talking about group
>> permissions. I'd make it 4700 or 4500 and set its ownership to
>> the one user who's allowed to execute it.
>
> Original requirement was to allow only one user to execute foo-bin *as root*
>
> Therefore, foo-bin must be owned by root :)

Oops, you're right.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Restricting who can run a set-user-id-root executable

<sllop3$upg$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16734&group=comp.unix.programmer#16734

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: root@127.0.0.1 (Noob)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sun, 31 Oct 2021 10:48:19 +0100
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <sllop3$upg$1@dont-email.me>
References: <sljmug$8di$2@dont-email.me> <slkael$8ac$1@news.xmission.com>
<slkk4u$l5m$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 31 Oct 2021 09:48:19 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5c50c5d5cf2e37741dc6b32f0282c47c";
logging-data="31536"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mKImE9pu0PCYF07qL6eTmhrN+9mQGG9o="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:l7Bci3jfj0Go2ybGoPZb7XU8rO0=
In-Reply-To: <slkk4u$l5m$1@dont-email.me>
Content-Language: en-US
 by: Noob - Sun, 31 Oct 2021 09:48 UTC

On 31/10/2021 01:23, John McCue wrote:

> Kenny McCormack wrote:
>
>> Noob wrote:
>>
>>> There's a different approach that would also work:
>>> 1) put foo-bin in user12345's group (chown root:user12345 foo-bin)
>>> 2) allow group to run foo-bin, not others (chmod 4750 foo-bin)
>>
>> My first (and best) thought was to do it via grops. Seems tailor-made for
>> this.
>>
>> I'd create a new group (Say, foo-bin-users) and add your user to that
>> group. This makes it easy to add others in the future.
>
> That was what I thought too, then I realized may be better
> to not bother with getuid(2) getgid(2) and just do:
>
> # chgrp foo-bin
> # chmod 750 foo-bin
>
> Then it is not tied to a specific hard-coded ID/Group
> and no setgid needed

Hello John,

I'm not sure I understand the specifics of your suggestion.
(And how it differs from Kenny's and my own second solution?)

(In solution #1, I used getuid.
In solution #2, I used "regular" Unix permissions.)

In your proposed solution,
What group does foo-bin belong to? (chgrp GROUP FILE)
Also, you dropped the set-user-id bit, this cannot work.

Regards.

Re: Restricting who can run a set-user-id-root executable

<sllp7a$1um$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16735&group=comp.unix.programmer#16735

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: root@127.0.0.1 (Noob)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sun, 31 Oct 2021 10:55:53 +0100
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <sllp7a$1um$1@dont-email.me>
References: <sljmug$8di$2@dont-email.me> <87lf2athnh.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 31 Oct 2021 09:55:54 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5c50c5d5cf2e37741dc6b32f0282c47c";
logging-data="2006"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0NrepsWgxYxTClNi7IxgUyNqty/mNIxA="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:zoQFwy5b36RL2b+AI3l+81nNmK8=
In-Reply-To: <87lf2athnh.fsf@bsb.me.uk>
Content-Language: en-US
 by: Noob - Sun, 31 Oct 2021 09:55 UTC

On 30/10/2021 21:52, Ben Bacarisse wrote:

> Noob writes:
>
>> I've written my first Linux set-user-id-root program (let's call it foo-bin)
>>
>> foo-bin is suid-root because:
>> 1) foo-bin is supposed to be run by an unprivileged user,
>> 2) foo-bin makes privileged system calls (unshare, chroot, mount, setgroups)
>>
>> I didn't want *every* unprivileged user to be able to run foo-bin.
>> Only user 12345 is allowed to run foo-bin.
>>
>> So I just added trivial code at the start of foo-bin:
>>
>> if (getuid() != 12345)
>> die("Bad credentials");
>
> Generally, this sort of thing is done using sudo rather than hard-wiring
> UIDs into source code. That sets my (code) teeth on edge!

Indeed, my solution above doesn't feel "right", I'll grant you that.

(It's worth noting that I work on an embedded system, where there are no
"real" users. User IDs are just used to isolate binaries from each other.)

In your solution, how would your sudo suggestion work?
You would add user12345 to the sudoers group?
But then user12345 could do anything that root can.
I want user12345 to be able to run foo-bin as root, nothing more.

Do you see any security issue with my solution #1?
I'll adopt solution #2 in production, but I wanted to hear people's opinion
as to why solution #1 fails ;)

Regards.

Re: Restricting who can run a set-user-id-root executable

<87zgqp8o4d.fsf@LkoBDZeT.terraraq.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16736&group=comp.unix.programmer#16736

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.nntp4.net!nntp.terraraq.uk!.POSTED.nntp.terraraq.uk!not-for-mail
From: invalid@invalid.invalid (Richard Kettlewell)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sun, 31 Oct 2021 10:50:10 +0000
Organization: terraraq NNTP server
Message-ID: <87zgqp8o4d.fsf@LkoBDZeT.terraraq.uk>
References: <sljmug$8di$2@dont-email.me> <87lf2athnh.fsf@bsb.me.uk>
<sllp7a$1um$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: mantic.terraraq.uk; posting-host="nntp.terraraq.uk:2a00:1098:0:86:1000:3f:0:2";
logging-data="23994"; mail-complaints-to="usenet@mantic.terraraq.uk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
Cancel-Lock: sha1:14iWu+p+bx5cWPGnMWucR+AdzrA=
X-Face: h[Hh-7npe<<b4/eW[]sat,I3O`t8A`(ej.H!F4\8|;ih)`7{@:A~/j1}gTt4e7-n*F?.Rl^
F<\{jehn7.KrO{!7=:(@J~]<.[{>v9!1<qZY,{EJxg6?Er4Y7Ng2\Ft>Z&W?r\c.!4DXH5PWpga"ha
+r0NzP?vnz:e/knOY)PI-
X-Boydie: NO
 by: Richard Kettlewell - Sun, 31 Oct 2021 10:50 UTC

Noob <root@127.0.0.1> writes:
> In your solution, how would your sudo suggestion work?
> You would add user12345 to the sudoers group?
> But then user12345 could do anything that root can.
> I want user12345 to be able to run foo-bin as root, nothing more.

sudo can supposedly restrict privileged execution of certain commands to
certain users. (I say “supposedly” due to its rather sad CVE record.)

> Do you see any security issue with my solution #1?
> I'll adopt solution #2 in production, but I wanted to hear people's opinion
> as to why solution #1 fails ;)

It works in its environment, but it’s not robust against changes to that
environment, e.g. if it gets moved to a different system, or the system
gets reinstalled for some reason, or the rules change about which
user(s) should be able to execute it. Whether relevant changes to its
environment are likely is not something anyone else can predict for you.

--
https://www.greenend.org.uk/rjk/

Re: Restricting who can run a set-user-id-root executable

<slm6r2$ogf$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16737&group=comp.unix.programmer#16737

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jmccue@fuzzball.mhome.org (John McCue)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sun, 31 Oct 2021 13:48:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <slm6r2$ogf$1@dont-email.me>
References: <sljmug$8di$2@dont-email.me> <slkael$8ac$1@news.xmission.com> <slkk4u$l5m$1@dont-email.me> <sllop3$upg$1@dont-email.me>
Reply-To: jmclnx@SPAMisBADgmail.com
Injection-Date: Sun, 31 Oct 2021 13:48:18 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="dfb0f7824787cd122302553d08376c30";
logging-data="25103"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VoTF/UaPwM7v7tWGdZoFp"
User-Agent: tin/2.4.4-20191224 ("Millburn") (OpenBSD/7.0 (amd64))
Cancel-Lock: sha1:UPczmSe7YRdPhe406JhNP6ATPS4=
X-OS-Version: OpenBSD 7.0 amd64
 by: John McCue - Sun, 31 Oct 2021 13:48 UTC

Noob <root@127.0.0.1> wrote:
> On 31/10/2021 01:23, John McCue wrote:
>
>> Kenny McCormack wrote:
>>
>>> Noob wrote:
<snip>

>> That was what I thought too, then I realized may be better
>> to not bother with getuid(2) getgid(2) and just do:
>>
>> # chgrp foo-bin
>> # chmod 750 foo-bin
>>
>> Then it is not tied to a specific hard-coded ID/Group
>> and no setgid needed
>
> Hello John,
>
> I'm not sure I understand the specifics of your suggestion.
> (And how it differs from Kenny's and my own second solution?)
>
> (In solution #1, I used getuid.
> In solution #2, I used "regular" Unix permissions.)
>
> In your proposed solution,
> What group does foo-bin belong to? (chgrp GROUP FILE)
> Also, you dropped the set-user-id bit, this cannot work.

foo-bin would be 750:
-rwxr-x--- 1 root foo-bin .... foo-bin

then only User IDs in group foo-bin would have execute
access to it. You would need to create a group named
foo-bin (or whatever you would like to use) and add users
you want to execute binary foo-bin to that new group.

You can even get fancier if you system supports ACLs.

https://en.wikipedia.org/wiki/Access-control_list

but the end result is you can avoid using a set[gu]id
and hardcoding a check in the binary.

>
> Regards.

--
csh(1) - "An elegant shell, for a more... civilized age."
- Paraphrasing Star Wars

Re: Restricting who can run a set-user-id-root executable

<87ee80aotf.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16738&group=comp.unix.programmer#16738

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweikusat@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Sun, 31 Oct 2021 21:04:28 +0000
Lines: 21
Message-ID: <87ee80aotf.fsf@doppelsaurus.mobileactivedefense.com>
References: <sljmug$8di$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net qZtar+2HHQPiqINvInovsQxv2IqrB3jUB/OHud572a1r01pf4=
Cancel-Lock: sha1:cxtx7AON4rAz5JEcEbI1vxKexnI= sha1:0BN0k0QBBoBE4hUEGv6GNVCEh/g=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Rainer Weikusat - Sun, 31 Oct 2021 21:04 UTC

Noob <root@127.0.0.1> writes:
> I've written my first Linux set-user-id-root program (let's call it foo-bin)
>
> foo-bin is suid-root because:
> 1) foo-bin is supposed to be run by an unprivileged user,
> 2) foo-bin makes privileged system calls (unshare, chroot, mount, setgroups)

[...]

> There's a different approach that would also work:
> 1) put foo-bin in user12345's group (chown root:user12345 foo-bin)
> 2) allow group to run foo-bin, not others (chmod 4750 foo-bin)

That's what I usually do as a decision re: who is or isn't allowed to
run this falls into the realm of administrative policy which shouldn't
be hardcoded (IMHO).

Also, 4710 is sufficient: It's not necessary to read a file in order to
execute it, ie, while the kernel obviously has to, processes running
with the uid of a user supposed to be allowed to execute a file don't
need to read its contents.

Re: Restricting who can run a set-user-id-root executable

<slnds7$n5q$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16739&group=comp.unix.programmer#16739

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: root@127.0.0.1 (Noob)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Mon, 1 Nov 2021 01:54:31 +0100
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <slnds7$n5q$1@dont-email.me>
References: <sljmug$8di$2@dont-email.me> <slkael$8ac$1@news.xmission.com>
<slkk4u$l5m$1@dont-email.me> <sllop3$upg$1@dont-email.me>
<slm6r2$ogf$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 1 Nov 2021 00:54:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2d32a28baf70354daba57af3592c285d";
logging-data="23738"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bdgz/DSHCMX96fjgR4lTSecuqRxk/weQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:4YewAdQ2+GKbKX4lXXVWiBBD2KI=
In-Reply-To: <slm6r2$ogf$1@dont-email.me>
Content-Language: en-US
 by: Noob - Mon, 1 Nov 2021 00:54 UTC

On 31/10/2021 14:48, John McCue wrote:

> Noob wrote:
>
>> (In solution #1, I used getuid.
>> In solution #2, I used "regular" Unix permissions.)
>>
>> In your proposed solution,
>> What group does foo-bin belong to? (chgrp GROUP FILE)
>> Also, you dropped the set-user-id bit, this cannot work.
>
> foo-bin would be 750:
> -rwxr-x--- 1 root foo-bin .... foo-bin
>
> then only User IDs in group foo-bin would have execute
> access to it. You would need to create a group named
> foo-bin (or whatever you would like to use) and add users
> you want to execute binary foo-bin to that new group.

As far as I can tell, your suggestion is the same as Kenny's.
He wrote: "I'd create a new group (say, foo-bin-users) and add
your user to that group."

It is also the same as my proposed solution #2 (I just used
a different group name).

Also, I can't strip the setuid bit off, otherwise foo-bin
won't run with root privileges.

> but the end result is you can avoid using a set[gu]id
> and hardcoding a check in the binary.

Right. That's what I did in my proposed solution #2.

It's not yet obvious to me (at this point) why it's a terrible idea
to hard-code the check in the binary, though.

Regards.

Re: Restricting who can run a set-user-id-root executable

<slne68$oka$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16740&group=comp.unix.programmer#16740

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: root@127.0.0.1 (Noob)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Mon, 1 Nov 2021 01:59:52 +0100
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <slne68$oka$1@dont-email.me>
References: <sljmug$8di$2@dont-email.me>
<87ee80aotf.fsf@doppelsaurus.mobileactivedefense.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 1 Nov 2021 00:59:52 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2d32a28baf70354daba57af3592c285d";
logging-data="25226"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX190MBtC2OXpCT9aLmwuJykOVAQwtZlJX9I="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:44WiTEyyB3L8m+dDNCf4c2jrwjk=
In-Reply-To: <87ee80aotf.fsf@doppelsaurus.mobileactivedefense.com>
Content-Language: en-US
 by: Noob - Mon, 1 Nov 2021 00:59 UTC

On 31/10/2021 22:04, Rainer Weikusat wrote:

> Noob writes:
>
>> I've written my first Linux set-user-id-root program (let's call it foo-bin)
>>
>> foo-bin is suid-root because:
>> 1) foo-bin is supposed to be run by an unprivileged user,
>> 2) foo-bin makes privileged system calls (unshare, chroot, mount, setgroups)
>
> [...]
>
>> There's a different approach that would also work:
>> 1) put foo-bin in user12345's group (chown root:user12345 foo-bin)
>> 2) allow group to run foo-bin, not others (chmod 4750 foo-bin)
>
> That's what I usually do as a decision re: who is or isn't allowed to
> run this falls into the realm of administrative policy which shouldn't
> be hardcoded (IMHO).

You make a convincing argument.

> Also, 4710 is sufficient: It's not necessary to read a file in order to
> execute it, ie, while the kernel obviously has to, processes running
> with the uid of a user supposed to be allowed to execute a file don't
> need to read its contents.

Your answer makes me wonder:
How much/little additional security do I get from mode 4710 instead of 4750?
In other words, what bad things can user12345 do if they can read the
ELF executable file?
Maybe disassemble the code? To prepare a ROP exploit in advance?

Regards.

Re: Restricting who can run a set-user-id-root executable

<slnhse$a4l$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16741&group=comp.unix.programmer#16741

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jmccue@fuzzball.mhome.org (John McCue)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Mon, 1 Nov 2021 02:02:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <slnhse$a4l$1@dont-email.me>
References: <sljmug$8di$2@dont-email.me> <slkael$8ac$1@news.xmission.com> <slkk4u$l5m$1@dont-email.me> <sllop3$upg$1@dont-email.me> <slm6r2$ogf$1@dont-email.me> <slnds7$n5q$1@dont-email.me>
Reply-To: jmclnx@SPAMisBADgmail.com
Injection-Date: Mon, 1 Nov 2021 02:02:54 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e37266c13609a1329bf669ceb6d8e7e9";
logging-data="10389"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iAq18U/phBNpb4c9my/Vr"
User-Agent: tin/2.4.4-20191224 ("Millburn") (OpenBSD/7.0 (amd64))
Cancel-Lock: sha1:glj6crgd3oEFMU6uJ4HzyannZ20=
X-OS-Version: OpenBSD 7.0 amd64
 by: John McCue - Mon, 1 Nov 2021 02:02 UTC

Noob <root@127.0.0.1> wrote:
>
> It's not yet obvious to me (at this point) why it's a terrible idea
> to hard-code the check in the binary, though.

The main issue with having the check you propose hard-coded
inside the program will only allow 1 specific user to
execute.

What happens if you want other people to run the program ?

Also there is no guarantee user '12345' does not already
exist on a different system.

You may be forced to maintain separate binaries on each
different system or maintain separate configuration file the
program reads in to determine who can run it.

To me, best to use security settings UN*X already provides
for 'free' instead of designing your own.

HTH
John

>
> Regards.

--
csh(1) - "An elegant shell, for a more... civilized age."
- Paraphrasing Star Wars

Re: Restricting who can run a set-user-id-root executable

<slnu9j$23il$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16742&group=comp.unix.programmer#16742

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Mon, 1 Nov 2021 05:34:43 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <slnu9j$23il$1@news.xmission.com>
References: <sljmug$8di$2@dont-email.me> <sllop3$upg$1@dont-email.me> <slm6r2$ogf$1@dont-email.me> <slnds7$n5q$1@dont-email.me>
Injection-Date: Mon, 1 Nov 2021 05:34:43 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="69205"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Mon, 1 Nov 2021 05:34 UTC

In article <slnds7$n5q$1@dont-email.me>, Noob <root@127.0.0.1> wrote:
....
>As far as I can tell, your suggestion is the same as Kenny's.
>He wrote: "I'd create a new group (say, foo-bin-users) and add
>your user to that group."

Right.

>It is also the same as my proposed solution #2 (I just used
>a different group name).

IIRC, your original post suggested using your user's already existing
group. This is somewhat less portable than creating a new group (speciic
to this purpose).

>Also, I can't strip the setuid bit off, otherwise foo-bin
>won't run with root privileges.

Right. I think that was just a routine "thinko" on Keith's part.

>> but the end result is you can avoid using a set[gu]id
>> and hardcoding a check in the binary.
>
>Right. That's what I did in my proposed solution #2.

Right.

>It's not yet obvious to me (at this point) why it's a terrible idea
>to hard-code the check in the binary, though.

There's nothing per se wrong with it - it will work - but it is just not
best practice - and not as "future-proof" as using a group would be.

--
The whole aim of practical politics is to keep the populace alarmed (and hence clamorous
to be led to safety) by menacing it with an endless series of hobgoblins, all of them imaginary.

H. L. Mencken

Re: Restricting who can run a set-user-id-root executable

<871r3zexbz.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16743&group=comp.unix.programmer#16743

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweikusat@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Mon, 01 Nov 2021 14:59:12 +0000
Lines: 16
Message-ID: <871r3zexbz.fsf@doppelsaurus.mobileactivedefense.com>
References: <sljmug$8di$2@dont-email.me> <sllop3$upg$1@dont-email.me>
<slm6r2$ogf$1@dont-email.me> <slnds7$n5q$1@dont-email.me>
<slnu9j$23il$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net Qt9g+K62fop7wdWy4ksPwAw0xGtNAWPdumgxYzgwoGgf3GD34=
Cancel-Lock: sha1:xclqN8GF7P1Se0tADrhOK/vmzfY= sha1:1NwpByDNsVNJjJ3RT3EuYsrRLOM=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Rainer Weikusat - Mon, 1 Nov 2021 14:59 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:
> In article <slnds7$n5q$1@dont-email.me>, Noob <root@127.0.0.1> wrote:

[...]

>>It's not yet obvious to me (at this point) why it's a terrible idea
>>to hard-code the check in the binary, though.
>
> There's nothing per se wrong with it - it will work - but it is just not
> best practice - and not as "future-proof" as using a group would be.

It "will work" for as long as all systems the binary is copied to will
always associate the intended user with the hard-coded UID. As there's
nothing in the binary which screams "I have 66771 hard-coded as UID for
user grmblfzz!", that's bound to break even on a single system as stuff
like this tends to be forgotten over time.

Re: Restricting who can run a set-user-id-root executable

<87wnlrdidl.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16744&group=comp.unix.programmer#16744

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweikusat@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Mon, 01 Nov 2021 15:07:34 +0000
Lines: 28
Message-ID: <87wnlrdidl.fsf@doppelsaurus.mobileactivedefense.com>
References: <sljmug$8di$2@dont-email.me>
<87ee80aotf.fsf@doppelsaurus.mobileactivedefense.com>
<slne68$oka$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net XDlBTbs7O/kiM2SB4Oxx6A+trgmG01O2Lh24TLsJ9OjlwnsTg=
Cancel-Lock: sha1:ah39f/rQEcl+qqoW3ta7y3taBwE= sha1:Lfdqeha2iZiokp4xBS2oGr8AnQA=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Rainer Weikusat - Mon, 1 Nov 2021 15:07 UTC

Noob <root@127.0.0.1> writes:
> On 31/10/2021 22:04, Rainer Weikusat wrote:
>> Noob writes:

[...]

>> Also, 4710 is sufficient: It's not necessary to read a file in order to
>> execute it, ie, while the kernel obviously has to, processes running
>> with the uid of a user supposed to be allowed to execute a file don't
>> need to read its contents.
>
> Your answer makes me wonder:
> How much/little additional security do I get from mode 4710 instead of 4750?
> In other words, what bad things can user12345 do if they can read the
> ELF executable file?
> Maybe disassemble the code? To prepare a ROP exploit in advance?

Some protection against someone analysing the binary in order to find a
way to exploit it. That's presumably more than a bit theoretical, hence,
this is something of a "ticking the box" exercise. OTOH, it can be done
easily and there's usually nothing which can be gained by allowing read
access.

I usually do it because I expect to have to deal with the output of
"pen testers" (aptly named as their work consists of testing that they
can use a pen to write down a list of possibly existing vulnerabilities
blindly) who will flag all unticked boxes they find somewhere as
Unticked !!1 (OMG !!2).

Re: Restricting who can run a set-user-id-root executable

<slrfm2$3r50$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16745&group=comp.unix.programmer#16745

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Tue, 2 Nov 2021 13:49:54 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <slrfm2$3r50$1@news.xmission.com>
References: <sljmug$8di$2@dont-email.me> <slnds7$n5q$1@dont-email.me> <slnu9j$23il$1@news.xmission.com> <871r3zexbz.fsf@doppelsaurus.mobileactivedefense.com>
Injection-Date: Tue, 2 Nov 2021 13:49:54 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="126112"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Tue, 2 Nov 2021 13:49 UTC

In article <871r3zexbz.fsf@doppelsaurus.mobileactivedefense.com>,
Rainer Weikusat <rweikusat@talktalk.net> wrote:
>gazelle@shell.xmission.com (Kenny McCormack) writes:
>> In article <slnds7$n5q$1@dont-email.me>, Noob <root@127.0.0.1> wrote:
>
>[...]
>
>>>It's not yet obvious to me (at this point) why it's a terrible idea
>>>to hard-code the check in the binary, though.
>>
>> There's nothing per se wrong with it - it will work - but it is just not
>> best practice - and not as "future-proof" as using a group would be.
>
>It "will work" for as long as all systems the binary is copied to will
>always associate the intended user with the hard-coded UID. As there's
>nothing in the binary which screams "I have 66771 hard-coded as UID for
>user grmblfzz!", that's bound to break even on a single system as stuff
>like this tends to be forgotten over time.

IOW, you agree with me, 100%. Thanks.

--
A racist, a Nazi, and a Klansman walk into a bar...

Bartender says, "What will it be, Mr. Trump?"

Re: Restricting who can run a set-user-id-root executable

<87h7cuo7xp.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16746&group=comp.unix.programmer#16746

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweikusat@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Restricting who can run a set-user-id-root executable
Date: Tue, 02 Nov 2021 16:09:54 +0000
Lines: 29
Message-ID: <87h7cuo7xp.fsf@doppelsaurus.mobileactivedefense.com>
References: <sljmug$8di$2@dont-email.me> <slnds7$n5q$1@dont-email.me>
<slnu9j$23il$1@news.xmission.com>
<871r3zexbz.fsf@doppelsaurus.mobileactivedefense.com>
<slrfm2$3r50$1@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net zMmzVh1R7cxGlmjeremClg565AO3HVsoJAxi5gM6tJnREfwpo=
Cancel-Lock: sha1:RovqmAf6ERo1Qm6IFYZit408Edk= sha1:1b5BMMgdInmjyFmJ0T5RCYzw4fA=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Rainer Weikusat - Tue, 2 Nov 2021 16:09 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:
> In article <871r3zexbz.fsf@doppelsaurus.mobileactivedefense.com>,
> Rainer Weikusat <rweikusat@talktalk.net> wrote:
>>gazelle@shell.xmission.com (Kenny McCormack) writes:
>>> In article <slnds7$n5q$1@dont-email.me>, Noob <root@127.0.0.1> wrote:
>>
>>[...]
>>
>>>>It's not yet obvious to me (at this point) why it's a terrible idea
>>>>to hard-code the check in the binary, though.
>>>
>>> There's nothing per se wrong with it - it will work - but it is just not
>>> best practice - and not as "future-proof" as using a group would be.
>>
>>It "will work" for as long as all systems the binary is copied to will
>>always associate the intended user with the hard-coded UID. As there's
>>nothing in the binary which screams "I have 66771 hard-coded as UID for
>>user grmblfzz!", that's bound to break even on a single system as stuff
>>like this tends to be forgotten over time.
>
> IOW, you agree with me, 100%. Thanks.

I don't. Hard-coding system configuration information will work for as
long as the binary is regarded as configuration and the system
configuration as binary, IOW, what's supposed to be changeable by users
becomes cast in stone in this way while developers can "save some work"
in exchange for that.

I consider this a wrong design choice.

Pages:12
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor