* [PATCH 1/2] Revert "hwclock: don't allow non-root access"
@ 2016-12-06 18:06 Marian Vomir
2016-12-06 18:06 ` [PATCH 2/2] sys-utils/hwclock: make hwclock check for CAP_SYS_TIME capability Marian Vomir
2016-12-06 23:40 ` [PATCH 1/2] Revert "hwclock: don't allow non-root access" J William Piggott
0 siblings, 2 replies; 9+ messages in thread
From: Marian Vomir @ 2016-12-06 18:06 UTC (permalink / raw)
To: util-linux
This reverts commit 687cc5d58942b24a9f4013c68876d8cbea907ab1.
There are cases when an unprivileged user wants to set the hardware clock.
The solution is to use capabilities, specifically CAP_SYS_TIME in this case.
---
sys-utils/hwclock.8.in | 15 +++++++++++++++
sys-utils/hwclock.c | 34 +++++++++++++++++++++++++++++-----
2 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/sys-utils/hwclock.8.in b/sys-utils/hwclock.8.in
index dec7902..5a7f762 100644
--- a/sys-utils/hwclock.8.in
+++ b/sys-utils/hwclock.8.in
@@ -577,6 +577,21 @@ This second field is not used under Linux and is always zero.
See also
.BR \%settimeofday (2).
.
+.SS User access and setuid
+.PP
+Sometimes, you need to install
+.B \%hwclock
+setuid root. If you want users other than the superuser to be able to
+display the clock value using the direct ISA I/O method, install it setuid
+root. If you have the rtc device interface on your system, or are on a non-ISA
+compatible system, there is probably no need for users to have the direct
+ISA I/O method, so do not bother. See the
+.BR \-\-rtc " option."
+.PP
+In any case, \fBhwclock\fR will not allow you to set anything unless you have the
+superuser real uid. (This restriction is not necessary if you haven't
+installed setuid root, but it's there for now.)
+.
.SS Hardware Clock Access Methods
.PP
.B \%hwclock
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index 4b201d7..880ba78 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -1633,6 +1633,8 @@ int main(int argc, char **argv)
* fractions.
*/
time_t set_time = 0; /* Time to which user said to set Hardware Clock */
+
+ bool permitted; /* User is permitted to do the function */
int rc, c;
/* Variables set by various options; show may also be set later */
@@ -1861,11 +1863,6 @@ int main(int argc, char **argv)
argc -= optind;
argv += optind;
- if (getuid() != 0) {
- warnx(_("Sorry, only the superuser can use the Hardware Clock."));
- hwclock_exit(EX_NOPERM);
- }
-
#ifdef HAVE_LIBAUDIT
if (testing != TRUE) {
if (adjust == TRUE || hctosys == TRUE || systohc == TRUE ||
@@ -1907,6 +1904,28 @@ int main(int argc, char **argv)
| setepoch | predict | compare | get))
show = 1; /* default to show */
+ if (getuid() == 0)
+ permitted = TRUE;
+ else {
+ /* program is designed to run setuid (in some situations) */
+ if ((set || systohc || adjust) && !testing) {
+ warnx(_("Sorry, only the superuser can change "
+ "the Hardware Clock."));
+ permitted = FALSE;
+ } else if ((systz || hctosys) && !testing) {
+ warnx(_("Sorry, only the superuser can change "
+ "the System Clock."));
+ permitted = FALSE;
+ } else if (setepoch && !testing) {
+ warnx(_("Sorry, only the superuser can change the "
+ "Hardware Clock epoch in the kernel."));
+ permitted = FALSE;
+ } else
+ permitted = TRUE;
+ }
+
+ if (!permitted)
+ hwclock_exit(EX_NOPERM);
#ifdef __linux__
if (getepoch || setepoch) {
@@ -2009,6 +2028,11 @@ void __attribute__((__noreturn__)) hwaudit_exit(int status)
* with any functions by these names, you will have unresolved external
* references when you link.
*
+ * The program is designed to run setuid superuser, since we need to be able
+ * to do direct I/O. (More to the point: we need permission to execute the
+ * iopl() system call). (However, if you use one of the methods other than
+ * direct ISA I/O to access the clock, no setuid is required).
+ *
* Here's some info on how we must deal with the time that elapses while
* this program runs: There are two major delays as we run:
*
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 2/2] sys-utils/hwclock: make hwclock check for CAP_SYS_TIME capability
2016-12-06 18:06 [PATCH 1/2] Revert "hwclock: don't allow non-root access" Marian Vomir
@ 2016-12-06 18:06 ` Marian Vomir
2016-12-06 23:40 ` [PATCH 1/2] Revert "hwclock: don't allow non-root access" J William Piggott
1 sibling, 0 replies; 9+ messages in thread
From: Marian Vomir @ 2016-12-06 18:06 UTC (permalink / raw)
To: util-linux
hwclock now checks if the capability to modify the clock (CAP_SYS_TIME) is set.
This allows the clock to be changed by unprivileged processes which have this capability.
---
sys-utils/Makemodule.am | 2 +-
sys-utils/hwclock.c | 59 +++++++++++++++++++++++++++++++++++--------------
2 files changed, 43 insertions(+), 18 deletions(-)
diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am
index f306e65..d40a4d9 100644
--- a/sys-utils/Makemodule.am
+++ b/sys-utils/Makemodule.am
@@ -412,5 +412,5 @@ if BUILD_SETPRIV
usrbin_exec_PROGRAMS += setpriv
dist_man_MANS += sys-utils/setpriv.1
setpriv_SOURCES = sys-utils/setpriv.c
-setpriv_LDADD = $(LDADD) -lcap-ng libcommon.la
+setpriv_LDADD = $(LDADD) -lcap-ng -lcap libcommon.la
endif
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index 880ba78..20ac6bf 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -66,6 +66,7 @@
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
+#include <sys/capability.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
@@ -1904,24 +1905,48 @@ int main(int argc, char **argv)
| setepoch | predict | compare | get))
show = 1; /* default to show */
- if (getuid() == 0)
- permitted = TRUE;
- else {
+ permitted = TRUE;
+ if (getuid() != 0) {
/* program is designed to run setuid (in some situations) */
- if ((set || systohc || adjust) && !testing) {
- warnx(_("Sorry, only the superuser can change "
- "the Hardware Clock."));
- permitted = FALSE;
- } else if ((systz || hctosys) && !testing) {
- warnx(_("Sorry, only the superuser can change "
- "the System Clock."));
- permitted = FALSE;
- } else if (setepoch && !testing) {
- warnx(_("Sorry, only the superuser can change the "
- "Hardware Clock epoch in the kernel."));
- permitted = FALSE;
- } else
- permitted = TRUE;
+ if (!testing &&
+ (set || systohc || adjust || systz || hctosys || setepoch)) {
+ cap_t cap;
+ cap_flag_value_t flag_val;
+ cap_value_t val;
+
+ cap = cap_get_proc();
+ if (cap == NULL) {
+ warnx(_("cap_get_proc failed"));
+ permitted = FALSE;
+ }
+
+ if (cap_from_name("cap_sys_time", &val) == -1) {
+ switch (errno) {
+ case EINVAL:
+ warnx(_("cap_from_name: invalid capability: 'cap_sys_time'"));
+ break;
+ case ENOMEM:
+ warnx(_("cap_from_name: out of memory"));
+ break;
+ default:
+ warnx(_("cap_from_name: unknown error"));
+ break;
+ }
+ permitted = FALSE;
+ }
+
+ if (cap_get_flag(cap, val, CAP_EFFECTIVE, &flag_val) == -1) {
+ warnx(_("cap_get_flag: invalid capability"));
+ permitted = FALSE;
+ }
+
+ if (flag_val != CAP_SET) {
+ warnx(_("Non-root cannot run hwclock without capability CAP_SYS_TIME set"));
+ permitted = FALSE;
+ }
+
+ cap_free(cap);
+ }
}
if (!permitted)
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 1/2] Revert "hwclock: don't allow non-root access"
2016-12-06 18:06 [PATCH 1/2] Revert "hwclock: don't allow non-root access" Marian Vomir
2016-12-06 18:06 ` [PATCH 2/2] sys-utils/hwclock: make hwclock check for CAP_SYS_TIME capability Marian Vomir
@ 2016-12-06 23:40 ` J William Piggott
2016-12-07 11:25 ` Karel Zak
1 sibling, 1 reply; 9+ messages in thread
From: J William Piggott @ 2016-12-06 23:40 UTC (permalink / raw)
To: Marian Vomir, util-linux
On 12/06/2016 01:06 PM, Marian Vomir wrote:
> This reverts commit 687cc5d58942b24a9f4013c68876d8cbea907ab1.
>
> There are cases when an unprivileged user wants to set the hardware clock.
This has never been allowed in over two decades of hwclock. I cannot
think of a legitimate reason to allow setting the Hardware Clock by a
normal user.
Having said that, while I agree with Karel's desire to remove all
mention of running hwclock with setuid, IMO the code should not have
been removed. Despite the comment directly above it, that code has
nothing to do with hwclock being run with setuid.
I would argue that there are some hwclock options intended for normal
users. A normal users should at least be able to display the Hardware
Clock time. In development of hwclock I use --test as a normal user for
all functions, including set function.
> The solution is to use capabilities, specifically CAP_SYS_TIME in this case.
> ---
> sys-utils/hwclock.8.in | 15 +++++++++++++++
> sys-utils/hwclock.c | 34 +++++++++++++++++++++++++++++-----
> 2 files changed, 44 insertions(+), 5 deletions(-)
>
> diff --git a/sys-utils/hwclock.8.in b/sys-utils/hwclock.8.in
> index dec7902..5a7f762 100644
> --- a/sys-utils/hwclock.8.in
> +++ b/sys-utils/hwclock.8.in
> @@ -577,6 +577,21 @@ This second field is not used under Linux and is always zero.
> See also
> .BR \%settimeofday (2).
> .
> +.SS User access and setuid
> +.PP
> +Sometimes, you need to install
> +.B \%hwclock
> +setuid root. If you want users other than the superuser to be able to
> +display the clock value using the direct ISA I/O method, install it setuid
> +root. If you have the rtc device interface on your system, or are on a non-ISA
> +compatible system, there is probably no need for users to have the direct
> +ISA I/O method, so do not bother. See the
> +.BR \-\-rtc " option."
> +.PP
> +In any case, \fBhwclock\fR will not allow you to set anything unless you have the
> +superuser real uid. (This restriction is not necessary if you haven't
> +installed setuid root, but it's there for now.)
> +.
> .SS Hardware Clock Access Methods
> .PP
> .B \%hwclock
> diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
> index 4b201d7..880ba78 100644
> --- a/sys-utils/hwclock.c
> +++ b/sys-utils/hwclock.c
> @@ -1633,6 +1633,8 @@ int main(int argc, char **argv)
> * fractions.
> */
> time_t set_time = 0; /* Time to which user said to set Hardware Clock */
> +
> + bool permitted; /* User is permitted to do the function */
> int rc, c;
>
> /* Variables set by various options; show may also be set later */
> @@ -1861,11 +1863,6 @@ int main(int argc, char **argv)
> argc -= optind;
> argv += optind;
>
> - if (getuid() != 0) {
> - warnx(_("Sorry, only the superuser can use the Hardware Clock."));
> - hwclock_exit(EX_NOPERM);
> - }
> -
> #ifdef HAVE_LIBAUDIT
> if (testing != TRUE) {
> if (adjust == TRUE || hctosys == TRUE || systohc == TRUE ||
> @@ -1907,6 +1904,28 @@ int main(int argc, char **argv)
> | setepoch | predict | compare | get))
> show = 1; /* default to show */
>
> + if (getuid() == 0)
> + permitted = TRUE;
> + else {
> + /* program is designed to run setuid (in some situations) */
> + if ((set || systohc || adjust) && !testing) {
> + warnx(_("Sorry, only the superuser can change "
> + "the Hardware Clock."));
> + permitted = FALSE;
> + } else if ((systz || hctosys) && !testing) {
> + warnx(_("Sorry, only the superuser can change "
> + "the System Clock."));
> + permitted = FALSE;
> + } else if (setepoch && !testing) {
> + warnx(_("Sorry, only the superuser can change the "
> + "Hardware Clock epoch in the kernel."));
> + permitted = FALSE;
> + } else
> + permitted = TRUE;
> + }
> +
> + if (!permitted)
> + hwclock_exit(EX_NOPERM);
>
> #ifdef __linux__
> if (getepoch || setepoch) {
> @@ -2009,6 +2028,11 @@ void __attribute__((__noreturn__)) hwaudit_exit(int status)
> * with any functions by these names, you will have unresolved external
> * references when you link.
> *
> + * The program is designed to run setuid superuser, since we need to be able
> + * to do direct I/O. (More to the point: we need permission to execute the
> + * iopl() system call). (However, if you use one of the methods other than
> + * direct ISA I/O to access the clock, no setuid is required).
> + *
> * Here's some info on how we must deal with the time that elapses while
> * this program runs: There are two major delays as we run:
> *
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 1/2] Revert "hwclock: don't allow non-root access"
2016-12-06 23:40 ` [PATCH 1/2] Revert "hwclock: don't allow non-root access" J William Piggott
@ 2016-12-07 11:25 ` Karel Zak
2016-12-08 16:03 ` marian.vomir
2016-12-09 2:09 ` J William Piggott
0 siblings, 2 replies; 9+ messages in thread
From: Karel Zak @ 2016-12-07 11:25 UTC (permalink / raw)
To: J William Piggott; +Cc: Marian Vomir, util-linux
On Tue, Dec 06, 2016 at 06:40:32PM -0500, J William Piggott wrote:
>
>
> On 12/06/2016 01:06 PM, Marian Vomir wrote:
> > This reverts commit 687cc5d58942b24a9f4013c68876d8cbea907ab1.
> >
> > There are cases when an unprivileged user wants to set the hardware clock.
>
> This has never been allowed in over two decades of hwclock. I cannot
> think of a legitimate reason to allow setting the Hardware Clock by a
> normal user.
Yes. It seems Marian has missed the goal of the commit
687cc5d58942b24a9f4013c68876d8cbea907ab1. It's not about permissions
detection.
We don't want to support use-case where hwclock(8) has extra
permissions (setuid or CAP_<something>) to set system time. The binary
is not designed for this purpose and it does not make sense to support
it -- less utils with extra permissions is better.
> Having said that, while I agree with Karel's desire to remove all
> mention of running hwclock with setuid, IMO the code should not have
> been removed. Despite the comment directly above it, that code has
> nothing to do with hwclock being run with setuid.
Maybe my patch seems too strict, but change docs is not enough, the
code matters. We want to be sure nobody uses hwclock as setuid,
especially if man page and code comments promised this non-sense.
> I would argue that there are some hwclock options intended for normal
> users. A normal users should at least be able to display the Hardware
> Clock time.
We can change it to support --show for non-root users, but the
question is if such change will have any practical effect, because for
example on Fedora we have:
$ ll /dev/rtc0
crw------- 1 root root 251, 0 Nov 28 10:46 /dev/rtc0
so
$ hwclock --debug --show
hwclock from util-linux 2.29.44-a99c0
hwclock: cannot open /dev/rtc: Permission denied
No usable clock interface found.
hwclock: Cannot access the Hardware Clock via any known method.
with the untested patch below. IMHO it's waste of time to try to be
smart in this area... ;-)
Karel
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index 21caeb2..ede6cfa 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -1859,11 +1859,6 @@ int main(int argc, char **argv)
argc -= optind;
argv += optind;
- if (getuid() != 0) {
- warnx(_("Sorry, only the superuser can use the Hardware Clock."));
- hwclock_exit(EX_NOPERM);
- }
-
#ifdef HAVE_LIBAUDIT
if (testing != TRUE) {
if (adjust == TRUE || hctosys == TRUE || systohc == TRUE ||
@@ -1906,6 +1901,11 @@ int main(int argc, char **argv)
show = 1; /* default to show */
+ if (!show && getuid() != 0) {
+ warnx(_("Sorry, only --show is allowed for non-root users."));
+ hwclock_exit(EX_NOPERM);
+ }
+
#ifdef __linux__
if (getepoch || setepoch) {
manipulate_epoch(getepoch, setepoch, epoch_option, testing);
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 1/2] Revert "hwclock: don't allow non-root access"
2016-12-07 11:25 ` Karel Zak
@ 2016-12-08 16:03 ` marian.vomir
2016-12-09 2:09 ` J William Piggott
2016-12-09 2:09 ` J William Piggott
1 sibling, 1 reply; 9+ messages in thread
From: marian.vomir @ 2016-12-08 16:03 UTC (permalink / raw)
To: J William Piggott, Karel Zak; +Cc: util-linux
Should user space utilities be checking permissions?
Is that not the role of the kernel?
Why the difference between setting the hardware clock and setting the
system time? A normal user can set the system time from any binary
with CAP_SYS_TIME, and a normal user can reboot, and rebooting on
some distros (eg. Ubuntu) updates the hardware clock from the system
time from an init script. So there is still a way around the
restriction in these distros.
Or is a user with CAP_SYS_TIME not considered "normal"?
On 7 Dec 2016 at 12:25, Karel Zak wrote:
> On Tue, Dec 06, 2016 at 06:40:32PM -0500, J William Piggott wrote:
> >
> >
> > On 12/06/2016 01:06 PM, Marian Vomir wrote:
> > > This reverts commit 687cc5d58942b24a9f4013c68876d8cbea907ab1.
> > >
> > > There are cases when an unprivileged user wants to set the hardware clock.
> >
> > This has never been allowed in over two decades of hwclock. I cannot
> > think of a legitimate reason to allow setting the Hardware Clock by a
> > normal user.
>
> Yes. It seems Marian has missed the goal of the commit
> 687cc5d58942b24a9f4013c68876d8cbea907ab1. It's not about permissions
> detection.
>
> We don't want to support use-case where hwclock(8) has extra
> permissions (setuid or CAP_<something>) to set system time. The binary
> is not designed for this purpose and it does not make sense to support
> it -- less utils with extra permissions is better.
>
> > Having said that, while I agree with Karel's desire to remove all
> > mention of running hwclock with setuid, IMO the code should not have
> > been removed. Despite the comment directly above it, that code has
> > nothing to do with hwclock being run with setuid.
>
> Maybe my patch seems too strict, but change docs is not enough, the
> code matters. We want to be sure nobody uses hwclock as setuid,
> especially if man page and code comments promised this non-sense.
>
> > I would argue that there are some hwclock options intended for normal
> > users. A normal users should at least be able to display the Hardware
> > Clock time.
>
> We can change it to support --show for non-root users, but the
> question is if such change will have any practical effect, because for
> example on Fedora we have:
>
> $ ll /dev/rtc0
> crw------- 1 root root 251, 0 Nov 28 10:46 /dev/rtc0
>
> so
>
> $ hwclock --debug --show
> hwclock from util-linux 2.29.44-a99c0
> hwclock: cannot open /dev/rtc: Permission denied
> No usable clock interface found.
> hwclock: Cannot access the Hardware Clock via any known method.
>
> with the untested patch below. IMHO it's waste of time to try to be
> smart in this area... ;-)
>
> Karel
>
>
>
> diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
> index 21caeb2..ede6cfa 100644
> --- a/sys-utils/hwclock.c
> +++ b/sys-utils/hwclock.c
> @@ -1859,11 +1859,6 @@ int main(int argc, char **argv)
> argc -= optind;
> argv += optind;
>
> - if (getuid() != 0) {
> - warnx(_("Sorry, only the superuser can use the Hardware Clock."));
> - hwclock_exit(EX_NOPERM);
> - }
> -
> #ifdef HAVE_LIBAUDIT
> if (testing != TRUE) {
> if (adjust == TRUE || hctosys == TRUE || systohc == TRUE ||
> @@ -1906,6 +1901,11 @@ int main(int argc, char **argv)
> show = 1; /* default to show */
>
>
> + if (!show && getuid() != 0) {
> + warnx(_("Sorry, only --show is allowed for non-root users."));
> + hwclock_exit(EX_NOPERM);
> + }
> +
> #ifdef __linux__
> if (getepoch || setepoch) {
> manipulate_epoch(getepoch, setepoch, epoch_option, testing);
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 1/2] Revert "hwclock: don't allow non-root access"
2016-12-08 16:03 ` marian.vomir
@ 2016-12-09 2:09 ` J William Piggott
0 siblings, 0 replies; 9+ messages in thread
From: J William Piggott @ 2016-12-09 2:09 UTC (permalink / raw)
To: marian.vomir, Karel Zak; +Cc: util-linux
On 12/08/2016 11:03 AM, marian.vomir@ni.com wrote:
> Should user space utilities be checking permissions?
> Is that not the role of the kernel?
>
> Why the difference between setting the hardware clock and setting the
> system time?
I think this is a valid point, Marian. One System Clock analog is
coreutils date(1) command. It can set the System Clock, which is
arguably a worse thing to do on a running system then setting he
Hardware Clock, and it does not make any permission checks. It simply
allows anyone to run it and relies on the system being configured to
block a normal user from setting it:
$ date 01010000
date: cannot set date: Operation not permitted
Fri Jan 1 00:00:00 EST 2016
It is not a utilities job to babysit the system administrator. Nor
should it dictate what the administrator is allowed to do.
I said previously that hwclock(8) historically has never allowed system
altering functions to anyone accept root... but that does not necessarily
make it the correct thing to do.
> A normal user can set the system time from any binary
> with CAP_SYS_TIME, and a normal user can reboot, and rebooting on
> some distros (eg. Ubuntu) updates the hardware clock from the system
> time from an init script. So there is still a way around the
> restriction in these distros.
>
> Or is a user with CAP_SYS_TIME not considered "normal"?
>
>
> On 7 Dec 2016 at 12:25, Karel Zak wrote:
>
>> On Tue, Dec 06, 2016 at 06:40:32PM -0500, J William Piggott wrote:
>>>
>>>
>>> On 12/06/2016 01:06 PM, Marian Vomir wrote:
>>>> This reverts commit 687cc5d58942b24a9f4013c68876d8cbea907ab1.
>>>>
>>>> There are cases when an unprivileged user wants to set the hardware clock.
>>>
>>> This has never been allowed in over two decades of hwclock. I cannot
>>> think of a legitimate reason to allow setting the Hardware Clock by a
>>> normal user.
>>
>> Yes. It seems Marian has missed the goal of the commit
>> 687cc5d58942b24a9f4013c68876d8cbea907ab1. It's not about permissions
>> detection.
>>
>> We don't want to support use-case where hwclock(8) has extra
>> permissions (setuid or CAP_<something>) to set system time. The binary
>> is not designed for this purpose and it does not make sense to support
>> it -- less utils with extra permissions is better.
>>
>>> Having said that, while I agree with Karel's desire to remove all
>>> mention of running hwclock with setuid, IMO the code should not have
>>> been removed. Despite the comment directly above it, that code has
>>> nothing to do with hwclock being run with setuid.
>>
>> Maybe my patch seems too strict, but change docs is not enough, the
>> code matters. We want to be sure nobody uses hwclock as setuid,
>> especially if man page and code comments promised this non-sense.
>>
>>> I would argue that there are some hwclock options intended for normal
>>> users. A normal users should at least be able to display the Hardware
>>> Clock time.
>>
>> We can change it to support --show for non-root users, but the
>> question is if such change will have any practical effect, because for
>> example on Fedora we have:
>>
>> $ ll /dev/rtc0
>> crw------- 1 root root 251, 0 Nov 28 10:46 /dev/rtc0
>>
>> so
>>
>> $ hwclock --debug --show
>> hwclock from util-linux 2.29.44-a99c0
>> hwclock: cannot open /dev/rtc: Permission denied
>> No usable clock interface found.
>> hwclock: Cannot access the Hardware Clock via any known method.
>>
>> with the untested patch below. IMHO it's waste of time to try to be
>> smart in this area... ;-)
>>
>> Karel
>>
>>
>>
>> diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
>> index 21caeb2..ede6cfa 100644
>> --- a/sys-utils/hwclock.c
>> +++ b/sys-utils/hwclock.c
>> @@ -1859,11 +1859,6 @@ int main(int argc, char **argv)
>> argc -= optind;
>> argv += optind;
>>
>> - if (getuid() != 0) {
>> - warnx(_("Sorry, only the superuser can use the Hardware Clock."));
>> - hwclock_exit(EX_NOPERM);
>> - }
>> -
>> #ifdef HAVE_LIBAUDIT
>> if (testing != TRUE) {
>> if (adjust == TRUE || hctosys == TRUE || systohc == TRUE ||
>> @@ -1906,6 +1901,11 @@ int main(int argc, char **argv)
>> show = 1; /* default to show */
>>
>>
>> + if (!show && getuid() != 0) {
>> + warnx(_("Sorry, only --show is allowed for non-root users."));
>> + hwclock_exit(EX_NOPERM);
>> + }
>> +
>> #ifdef __linux__
>> if (getepoch || setepoch) {
>> manipulate_epoch(getepoch, setepoch, epoch_option, testing);
>>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe util-linux" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] Revert "hwclock: don't allow non-root access"
2016-12-07 11:25 ` Karel Zak
2016-12-08 16:03 ` marian.vomir
@ 2016-12-09 2:09 ` J William Piggott
2016-12-09 8:52 ` Karel Zak
1 sibling, 1 reply; 9+ messages in thread
From: J William Piggott @ 2016-12-09 2:09 UTC (permalink / raw)
To: Karel Zak; +Cc: Marian Vomir, util-linux
On 12/07/2016 06:25 AM, Karel Zak wrote:
> On Tue, Dec 06, 2016 at 06:40:32PM -0500, J William Piggott wrote:
>>
>>
>> On 12/06/2016 01:06 PM, Marian Vomir wrote:
>>> This reverts commit 687cc5d58942b24a9f4013c68876d8cbea907ab1.
>>>
>>> There are cases when an unprivileged user wants to set the hardware clock.
>>
>> This has never been allowed in over two decades of hwclock. I cannot
>> think of a legitimate reason to allow setting the Hardware Clock by a
>> normal user.
>
> Yes. It seems Marian has missed the goal of the commit
> 687cc5d58942b24a9f4013c68876d8cbea907ab1. It's not about permissions
> detection.
>
> We don't want to support use-case where hwclock(8) has extra
> permissions (setuid or CAP_<something>) to set system time. The binary
> is not designed for this purpose and it does not make sense to support
> it -- less utils with extra permissions is better.
>
>> Having said that, while I agree with Karel's desire to remove all
>> mention of running hwclock with setuid, IMO the code should not have
>> been removed. Despite the comment directly above it, that code has
>> nothing to do with hwclock being run with setuid.
>
> Maybe my patch seems too strict, but change docs is not enough, the
> code matters. We want to be sure nobody uses hwclock as setuid,
> especially if man page and code comments promised this non-sense.
I agree that setuid should be removed from the man-page and source
comments. I do not think the code was a problem; removing it does not
prevent running it with setuid. It only prevents users from access to
the benign read only functions of hwclock which they have historically
had.
>
>> I would argue that there are some hwclock options intended for normal
>> users. A normal users should at least be able to display the Hardware
>> Clock time.
>
> We can change it to support --show for non-root users, but the
> question is if such change will have any practical effect, because for
> example on Fedora we have:
>
> $ ll /dev/rtc0
> crw------- 1 root root 251, 0 Nov 28 10:46 /dev/rtc0
>
> so
>
> $ hwclock --debug --show
> hwclock from util-linux 2.29.44-a99c0
> hwclock: cannot open /dev/rtc: Permission denied
> No usable clock interface found.
> hwclock: Cannot access the Hardware Clock via any known method.
>
$ ls -l /dev/rtc0
crw-r--r-- 1 root root 254, 0 2016-12-08 09:50:26 /dev/rtc0
$ /sbin/hwclock
Thu 08 Dec 2016 08:40:08 PM EST .123162 seconds
Perhaps Fedora sets perms that way because it thinks hwclock is
irrelevant for systemd platforms.
> with the untested patch below. IMHO it's waste of time to try to be
> smart in this area... ;-)
>
> Karel
>
>
>
> diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
> index 21caeb2..ede6cfa 100644
> --- a/sys-utils/hwclock.c
> +++ b/sys-utils/hwclock.c
> @@ -1859,11 +1859,6 @@ int main(int argc, char **argv)
> argc -= optind;
> argv += optind;
>
> - if (getuid() != 0) {
> - warnx(_("Sorry, only the superuser can use the Hardware Clock."));
> - hwclock_exit(EX_NOPERM);
> - }
> -
> #ifdef HAVE_LIBAUDIT
> if (testing != TRUE) {
> if (adjust == TRUE || hctosys == TRUE || systohc == TRUE ||
> @@ -1906,6 +1901,11 @@ int main(int argc, char **argv)
> show = 1; /* default to show */
>
>
> + if (!show && getuid() != 0) {
> + warnx(_("Sorry, only --show is allowed for non-root users."));
> + hwclock_exit(EX_NOPERM);
> + }
> +
> #ifdef __linux__
> if (getepoch || setepoch) {
> manipulate_epoch(getepoch, setepoch, epoch_option, testing);
>
> --
> To unsubscribe from this list: send the line "unsubscribe util-linux" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 1/2] Revert "hwclock: don't allow non-root access"
2016-12-09 2:09 ` J William Piggott
@ 2016-12-09 8:52 ` Karel Zak
2016-12-09 8:54 ` Karel Zak
0 siblings, 1 reply; 9+ messages in thread
From: Karel Zak @ 2016-12-09 8:52 UTC (permalink / raw)
To: J William Piggott; +Cc: Marian Vomir, util-linux
On Thu, Dec 08, 2016 at 09:09:15PM -0500, J William Piggott wrote:
> On 12/07/2016 06:25 AM, Karel Zak wrote:
> > Maybe my patch seems too strict, but change docs is not enough, the
> > code matters. We want to be sure nobody uses hwclock as setuid,
> > especially if man page and code comments promised this non-sense.
>
> I agree that setuid should be removed from the man-page and source
> comments. I do not think the code was a problem; removing it does not
See 687cc5d58942b24a9f4013c68876d8cbea907ab1, it removes many checks.
It wasn't about comments only.
> prevent running it with setuid. It only prevents users from access to
> the benign read only functions of hwclock which they have historically
> had.
I agree that kernel is the place where we need to check permissions,
so I have removed the if (getuid() != 0)
https://github.com/karelzak/util-linux/commit/f4e61504a457395018c02bafcf17d1e3f8644b78
let's hope nobody uses it as setuid.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 1/2] Revert "hwclock: don't allow non-root access"
2016-12-09 8:52 ` Karel Zak
@ 2016-12-09 8:54 ` Karel Zak
0 siblings, 0 replies; 9+ messages in thread
From: Karel Zak @ 2016-12-09 8:54 UTC (permalink / raw)
To: J William Piggott; +Cc: Marian Vomir, util-linux
On Fri, Dec 09, 2016 at 09:52:39AM +0100, Karel Zak wrote:
> On Thu, Dec 08, 2016 at 09:09:15PM -0500, J William Piggott wrote:
> > On 12/07/2016 06:25 AM, Karel Zak wrote:
> > > Maybe my patch seems too strict, but change docs is not enough, the
> > > code matters. We want to be sure nobody uses hwclock as setuid,
> > > especially if man page and code comments promised this non-sense.
> >
> > I agree that setuid should be removed from the man-page and source
> > comments. I do not think the code was a problem; removing it does not
>
> See 687cc5d58942b24a9f4013c68876d8cbea907ab1, it removes many checks.
> It wasn't about comments only.
>
> > prevent running it with setuid. It only prevents users from access to
> > the benign read only functions of hwclock which they have historically
> > had.
>
> I agree that kernel is the place where we need to check permissions,
> so I have removed the if (getuid() != 0)
>
> https://github.com/karelzak/util-linux/commit/f4e61504a457395018c02bafcf17d1e3f8644b78
>
> let's hope nobody uses it as setuid.
We will need big fat note in the v2.30 ReleaseNotes to make sure
downstream maintainers don't use it with some extra permissions.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2016-12-09 8:54 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-06 18:06 [PATCH 1/2] Revert "hwclock: don't allow non-root access" Marian Vomir
2016-12-06 18:06 ` [PATCH 2/2] sys-utils/hwclock: make hwclock check for CAP_SYS_TIME capability Marian Vomir
2016-12-06 23:40 ` [PATCH 1/2] Revert "hwclock: don't allow non-root access" J William Piggott
2016-12-07 11:25 ` Karel Zak
2016-12-08 16:03 ` marian.vomir
2016-12-09 2:09 ` J William Piggott
2016-12-09 2:09 ` J William Piggott
2016-12-09 8:52 ` Karel Zak
2016-12-09 8:54 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox