From: Xiao Yang <yangx.jy@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] read_all: Drop privileges
Date: Thu, 17 May 2018 18:20:48 +0800 [thread overview]
Message-ID: <5AFD5780.7040107@cn.fujitsu.com> (raw)
In-Reply-To: <20180516114438.GA26490@rei>
On 2018/05/16 19:44, Cyril Hrubis wrote:
> Hi!
>> If the permission of /dev/watchdog was 0660(default permission on RHEL6), Reading /dev/watchdog as nobody
>> user failed, but still led to system reboot.
> If unprivileged user can reboot the system it's a bug.
Hi Cyril,
Sorry, it seems a bug in open(2) instead of watchdog.
You can reproduce the issue by running the following test.c:
----------------------------------------------------------------------------------------------------------
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pwd.h>
#include <unistd.h>
#include <stdlib.h>
static void switch_privs(void)
{
struct passwd *nobody;
int ret;
nobody = getpwnam("nobody");
if (nobody == NULL) {
printf("getpwnam(nobody) failed with errno %d\n", errno);
exit(1);
}
ret = setgid(nobody->pw_gid);
if (ret < 0) {
printf("Failed to use nobody gid with errno %d\n", errno);
exit(1);
}
ret = setuid(nobody->pw_uid);
if (ret < 0) {
printf("Failed to use nobody uid with errno %d\n", errno);
exit(1);
}
}
int main(void)
{
int fd;
umask(0);
fd = open("testfile", O_RDWR | O_CREAT, 0660);
if (fd < 0) {
printf("open(testfile) failed with errno %d\n", errno);
return 1;
}
close(fd);
switch_privs();
fd = open("testfile", O_RDWR);
if (fd < 0) {
printf("open(testfile) failed with errno %d\n", errno);
return 1;
}
printf("open(testfile) succeeded unexpectedly\n");
close(fd);
}
------------------------------------------------------------------------------------------------------------
# gcc -o test test.c
# ./test
open(testfile) succeeded unexpectedly
We created a test file with 0660 mode as root user, and opened the test
file as nobody user switched by setuid() and setgid().
Running this test got success rather than EACCES. Do you think this is
a bug or i misunderstand the permissions of file?
Thanks,
Xiao Yang
next prev parent reply other threads:[~2018-05-17 10:20 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-15 9:51 [LTP] [PATCH] read_all: Drop privileges Richard Palethorpe
2018-05-15 10:30 ` Cyril Hrubis
2018-05-15 10:55 ` Richard Palethorpe
2018-05-15 10:57 ` Cyril Hrubis
2018-05-15 11:18 ` Punit Agrawal
2018-05-15 12:34 ` Richard Palethorpe
2018-05-15 11:23 ` Punit Agrawal
2018-05-16 9:39 ` Xiao Yang
2018-05-16 11:44 ` Cyril Hrubis
2018-05-17 10:20 ` Xiao Yang [this message]
2018-05-18 17:09 ` Cyril Hrubis
2018-05-19 9:04 ` Xiao Yang
2018-05-19 9:22 ` [LTP] [PATCH] fs/read_all: Clear suplementary groups before droping privileges Xiao Yang
2018-05-22 10:26 ` Richard Palethorpe
2018-05-22 10:56 ` Cyril Hrubis
2018-05-22 10:54 ` Cyril Hrubis
2018-05-15 11:00 ` [LTP] [PATCH v2] read_all: Drop privileges Richard Palethorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5AFD5780.7040107@cn.fujitsu.com \
--to=yangx.jy@cn.fujitsu.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox