public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* hwclock --compare segfaults when run as normal user
@ 2014-07-26 12:40 Benno Schulenberg
  2014-07-26 14:48 ` Sami Kerola
  0 siblings, 1 reply; 6+ messages in thread
From: Benno Schulenberg @ 2014-07-26 12:40 UTC (permalink / raw)
  To: Util-Linux; +Cc: Ondrej Oprala


Hi,

On my system there is no /etc/adjtime file, and then:

$ ./hwclock --compare
Segmentation fault

When run as root, it runs fine.


$ ./hwclock --version
hwclock from util-linux 2.25

Benno

-- 
http://www.fastmail.fm - mmm... Fastmail...


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: hwclock --compare segfaults when run as normal user
  2014-07-26 12:40 hwclock --compare segfaults when run as normal user Benno Schulenberg
@ 2014-07-26 14:48 ` Sami Kerola
  2014-07-26 16:05   ` Benno Schulenberg
  0 siblings, 1 reply; 6+ messages in thread
From: Sami Kerola @ 2014-07-26 14:48 UTC (permalink / raw)
  To: Benno Schulenberg; +Cc: Util-Linux, Ondrej Oprala

On 26 July 2014 13:40, Benno Schulenberg <bensberg@justemail.net> wrote:
> On my system there is no /etc/adjtime file, and then:
>
> $ ./hwclock --compare
> Segmentation fault
>
> When run as root, it runs fine.
>
>
> $ ./hwclock --version
> hwclock from util-linux 2.25

Hi Benno,

I tried to reproduce the issue without success. If you have core file
could you try to gdb backtrace it?

-- 
Sami Kerola
http://www.iki.fi/kerolasa/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: hwclock --compare segfaults when run as normal user
  2014-07-26 14:48 ` Sami Kerola
@ 2014-07-26 16:05   ` Benno Schulenberg
  2014-07-28 11:12     ` Karel Zak
  0 siblings, 1 reply; 6+ messages in thread
From: Benno Schulenberg @ 2014-07-26 16:05 UTC (permalink / raw)
  To: kerolasa; +Cc: Util-Linux, Ondrej Oprala


On Sat, Jul 26, 2014, at 16:48, Sami Kerola wrote:
> On 26 July 2014 13:40, Benno Schulenberg <bensberg@justemail.net> wrote:
> > On my system there is no /etc/adjtime file, and then:
> >
> > $ ./hwclock --compare
> > Segmentation fault
> 
> I tried to reproduce the issue without success. If you have core file
> could you try to gdb backtrace it?

(gdb) run --compare
Starting program: /home/ben/util-linux-2.25/hwclock --compare

Program received signal SIGSEGV, Segmentation fault.
0x0804cf71 in outb () at /usr/include/sys/io.h:99
99	  __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));

(gdb) bt
#0  0x0804cf71 in outb () at /usr/include/sys/io.h:99
#1  cmos_read () at sys-utils/hwclock-cmos.c:348
#2  atomic () at sys-utils/hwclock-cmos.c:307
#3  hclock_read () at sys-utils/hwclock-cmos.c:456
#4  cmos_clock_busy () at sys-utils/hwclock-cmos.c:472
#5  synchronize_to_clock_tick_cmos () at sys-utils/hwclock-cmos.c:484
#6  0x08049919 in synchronize_to_clock_tick () at sys-utils/hwclock.c:348
#7  0x0804c578 in compare_clock (argc=<value optimized out>, argv=0xbffff414) at sys-utils/hwclock.c:1502
#8  main (argc=<value optimized out>, argv=0xbffff414) at sys-utils/hwclock.c:1941

Benno

-- 
http://www.fastmail.fm - Choose from over 50 domains or use your own


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: hwclock --compare segfaults when run as normal user
  2014-07-26 16:05   ` Benno Schulenberg
@ 2014-07-28 11:12     ` Karel Zak
  2014-07-28 18:50       ` Benno Schulenberg
  0 siblings, 1 reply; 6+ messages in thread
From: Karel Zak @ 2014-07-28 11:12 UTC (permalink / raw)
  To: Benno Schulenberg; +Cc: kerolasa, Util-Linux

On Sat, Jul 26, 2014 at 06:05:09PM +0200, Benno Schulenberg wrote:
> 
> On Sat, Jul 26, 2014, at 16:48, Sami Kerola wrote:
> > On 26 July 2014 13:40, Benno Schulenberg <bensberg@justemail.net> wrote:
> > > On my system there is no /etc/adjtime file, and then:
> > >
> > > $ ./hwclock --compare
> > > Segmentation fault
> > 
> > I tried to reproduce the issue without success. If you have core file

because you have RTC and Benno has cmos I guess

> > could you try to gdb backtrace it?

> 
> (gdb) run --compare
> Starting program: /home/ben/util-linux-2.25/hwclock --compare
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x0804cf71 in outb () at /usr/include/sys/io.h:99
> 99	  __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));
> 
> (gdb) bt
> #0  0x0804cf71 in outb () at /usr/include/sys/io.h:99
> #1  cmos_read () at sys-utils/hwclock-cmos.c:348
> #2  atomic () at sys-utils/hwclock-cmos.c:307
> #3  hclock_read () at sys-utils/hwclock-cmos.c:456

 I have no way how to to test it, but can you try the patch below?

  Karel


>From 8fe55779b04e961d9e99bba7e1df382b71b63095 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Mon, 28 Jul 2014 13:00:54 +0200
Subject: [PATCH] hwclock: check for permissions before use clock interface

Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
---
 sys-utils/hwclock.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index a934ace..474e04f 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -1495,6 +1495,9 @@ static int compare_clock (const bool utc, const bool local_opt)
 	bool hclock_valid = FALSE, universal, first_pass = TRUE;
 	int rc;
 
+	if (ur->get_permissions())
+		return EX_NOPERM;
+
 	/* dummy call for increased precision */
 	gettimeofday(&tv, NULL);
 
@@ -1893,7 +1896,7 @@ int main(int argc, char **argv)
 	}
 
 	if (!(show | set | systohc | hctosys | systz | adjust | getepoch
-	      | setepoch | predict))
+	      | setepoch | predict | compare))
 		show = 1;	/* default to show */
 
 	if (getuid() == 0)
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: hwclock --compare segfaults when run as normal user
  2014-07-28 11:12     ` Karel Zak
@ 2014-07-28 18:50       ` Benno Schulenberg
  2014-07-29  6:27         ` Karel Zak
  0 siblings, 1 reply; 6+ messages in thread
From: Benno Schulenberg @ 2014-07-28 18:50 UTC (permalink / raw)
  To: Karel Zak; +Cc: kerolasa, Util-Linux


On Mon, Jul 28, 2014, at 13:12, Karel Zak wrote:
>  I have no way how to to test it, but can you try the patch below?
> [...]
>  
> +	if (ur->get_permissions())
> +		return EX_NOPERM;
> +

Yes, looks better now:

$ ./hwclock --compare
hwclock: unable to get I/O port access:  the iopl(3) call failed.: Operation not permitted
hwclock: Probably you need root privileges.

Benno

-- 
http://www.fastmail.fm - Email service worth paying for. Try it for free

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: hwclock --compare segfaults when run as normal user
  2014-07-28 18:50       ` Benno Schulenberg
@ 2014-07-29  6:27         ` Karel Zak
  0 siblings, 0 replies; 6+ messages in thread
From: Karel Zak @ 2014-07-29  6:27 UTC (permalink / raw)
  To: Benno Schulenberg; +Cc: kerolasa, Util-Linux

On Mon, Jul 28, 2014 at 08:50:48PM +0200, Benno Schulenberg wrote:
> 
> On Mon, Jul 28, 2014, at 13:12, Karel Zak wrote:
> >  I have no way how to to test it, but can you try the patch below?
> > [...]
> >  
> > +	if (ur->get_permissions())
> > +		return EX_NOPERM;
> > +
> 
> Yes, looks better now:
> 
> $ ./hwclock --compare
> hwclock: unable to get I/O port access:  the iopl(3) call failed.: Operation not permitted
> hwclock: Probably you need root privileges.

 Applied, thanks.

    Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-07-29  6:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-26 12:40 hwclock --compare segfaults when run as normal user Benno Schulenberg
2014-07-26 14:48 ` Sami Kerola
2014-07-26 16:05   ` Benno Schulenberg
2014-07-28 11:12     ` Karel Zak
2014-07-28 18:50       ` Benno Schulenberg
2014-07-29  6:27         ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox