Skip to contentSkip to conversation

some patches for the ptp framework

PATCH In review Torben Hohn 6 participants 25 messages Mar 3, 2011 – Mar 12, 2011

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

patches 1 and 3 apply on top of tip:core/timer

patch 2 also requires Richards ptp v12 1/4 for the ptp class. modulo a small conflict in drivers/ptp/Makefile and Kconfig. because i had added his ixp driver, which the software clock is based on.

Richards Patchset didnt apply to tip:core/timer as is. which branch is it based on ?

#1 lore raw

PATCH 1/3 remove __cpuinit from mwait_usable()

mwait_usable() is used by native_play_dead() which is not __cpuinit.

Cc Richard Cochran <[email protected]>
Cc John Stultz <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/include/asm/cpu.h |    2 +-
 arch/x86/kernel/process.c  |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/cpu.h +1 -1
index 6e6e755..4564c8e 100644
@@ -32,6 +32,6 @@ extern void arch_unregister_cpu(int);
 
 DECLARE_PER_CPU(int, cpu_state);
 
-int __cpuinit mwait_usable(const struct cpuinfo_x86 *);
+int mwait_usable(const struct cpuinfo_x86 *);
 
 #endif /* _ASM_X86_CPU_H */
arch/x86/kernel/process.c +1 -1
index e764fc0..3c189e9 100644
@@ -506,7 +506,7 @@ static void poll_idle(void)
 #define MWAIT_ECX_EXTENDED_INFO		0x01
 #define MWAIT_EDX_C1			0xf0
 
-int __cpuinit mwait_usable(const struct cpuinfo_x86 *c)
+int mwait_usable(const struct cpuinfo_x86 *c)
 {
 	u32 eax, ebx, ecx, edx;
 
Signature · 1 line
1.7.2.3
#2 lore raw

PATCH 2/3 ptp: add a software clock based on clock_monotonic_raw

In reply to Torben Hohn

First version of a software clock. Not very useful yet, as it doesnt generate events, but at least it allows for testing the ptp framework without special hardware.

Cc Richard Cochran <[email protected]>
Cc John Stultz <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 drivers/ptp/Kconfig        |    6 +
 drivers/ptp/Makefile       |    1 +
 drivers/ptp/ptp_software.c |  221 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+), 0 deletions(-)
 create mode 100644 drivers/ptp/ptp_software.c
drivers/ptp/Kconfig +6 -0
index d99e6f9..0427361 100644
@@ -40,4 +40,10 @@ config PTP_1588_CLOCK_IXP46X
 	  To compile this driver as a module, choose M here: the module
 	  will be called ptp_ixp46x.
 
+config PTP_1588_CLOCK_SOFTWARE
+	tristate "software PTP clock"
+	depends on PTP_1588_CLOCK
+	help
+	  This driver adds a software PTP clock. 
+
 endmenu
drivers/ptp/Makefile +1 -0
index f6933e8..8f18a55 100644
@@ -5,3 +5,4 @@
 ptp-y					:= ptp_clock.o ptp_chardev.o ptp_sysfs.o
 obj-$(CONFIG_PTP_1588_CLOCK)		+= ptp.o
 obj-$(CONFIG_PTP_1588_CLOCK_IXP46X)	+= ptp_ixp46x.o
+obj-$(CONFIG_PTP_1588_CLOCK_SOFTWARE)	+= ptp_software.o
drivers/ptp/ptp_software.c new file +221 -0

221 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#3 lore raw

Re: [PATCH 2/3] ptp: add a software clock based on clock_monotonic_raw

Quoted 3 lines · Torben Hohn

First version of a software clock. Not very useful yet, as it doesnt generate events, but at least it allows for testing the ptp framework without special hardware.

So in the past, I pushed back on Richard for having something similar, as I'm not psyched about duplicating interfaces. However, your implementation is CLOCK_MONOTONIC_RAW instead of CLOCK_REALTIME and it keeps the adjustments internal, I'm not as opposed.

So I think having such test driver is probably reasonable, but please make it more explicit that it is just a testing driver, and not something someone should try to use.

drivers/ptp/ptp_software.c line 41

Quoted 8 lines
drivers/ptp/ptp_software.c new file +8 -0
+
+struct ixp_clock {
+	struct ptp_clock *ptp_clock;
+	struct ptp_clock_info caps;
+	s64 offset_ns;
+	struct timespec last_timestamp;
+	s32 freq;
+};

Probably should rename things from ixp_*

thanks
-john

maintainer
#4 lore raw

Re: [PATCH 2/3] ptp: add a software clock based on clock_monotonic_raw

Quoted 9 lines · john stultz
Quoted 3 lines · Torben Hohn

First version of a software clock. Not very useful yet, as it doesnt generate events, but at least it allows for testing the ptp framework without special hardware.

So in the past, I pushed back on Richard for having something similar, as I'm not psyched about duplicating interfaces. However, your implementation is CLOCK_MONOTONIC_RAW instead of CLOCK_REALTIME and it keeps the adjustments internal, I'm not as opposed.

(Aha! So it is okay after all ;)

I do think a software only PHC will make it easier for people to get started with the new interface. I have been carrying along such a patch privately for my own testing.

Thanks,

Richard

author
#5 lore raw

Re: [PATCH 2/3] ptp: add a software clock based on clock_monotonic_raw

Quoted 11 lines · Richard Cochran
Quoted 9 lines · john stultz
Quoted 3 lines · Torben Hohn

First version of a software clock. Not very useful yet, as it doesnt generate events, but at least it allows for testing the ptp framework without special hardware.

So in the past, I pushed back on Richard for having something similar, as I'm not psyched about duplicating interfaces. However, your implementation is CLOCK_MONOTONIC_RAW instead of CLOCK_REALTIME and it keeps the adjustments internal, I'm not as opposed.

Quoted 5 lines

(Aha! So it is okay after all ;)

I do think a software only PHC will make it easier for people to get started with the new interface. I have been carrying along such a patch privately for my own testing.

can you post your patch then ?
if john likes somthing better in my implementation, we should merge them.

i will be away for the next week, so its probably up to you.

i am still trying to find out, whether 802.1AS will spec accurate ptp clocks. i have the feeling that they wont.
the main concern is synchronicity of the clock inside all devices of the timing domain. that this clock i running at the same frequency as the wallclock is not important.

here is a pretty confused mail about this:
http://article.gmane.org/gmane.comp.audio.jackit/23606

i hope this thread will yield more useful information as it develops.

i am currently acting under the assumption, that a device like this:
http://www.xmos.com/products/reference-designs/avbl2
would need to be the ptp master when the computer doesnt have h/w timestamping in its NIC.
i am also assuming that the clock in that device would be crappy.

so we wouldnt want to servo CLOCK_REALTIME after that crappy clock. but we want an instance of that clock as accurate as possible inside the computer. so that we can bind streaming apps to this clock.

Signature · 1 line
torben Hohn
#6 lore raw

Re: [PATCH 2/3] ptp: add a software clock based on clock_monotonic_raw

In reply to Richard Cochran
Quoted 11 lines · Richard Cochran
Quoted 9 lines · john stultz
Quoted 3 lines · Torben Hohn

First version of a software clock. Not very useful yet, as it doesnt generate events, but at least it allows for testing the ptp framework without special hardware.

So in the past, I pushed back on Richard for having something similar, as I'm not psyched about duplicating interfaces. However, your implementation is CLOCK_MONOTONIC_RAW instead of CLOCK_REALTIME and it keeps the adjustments internal, I'm not as opposed.

Quoted 5 lines

(Aha! So it is okay after all ;)

I do think a software only PHC will make it easier for people to get started with the new interface. I have been carrying along such a patch privately for my own testing.

Consistency is but a hobgoblin... :)

But seriously, do forgive me if I misunderstood your earlier patches with this respect. I thought it was just exporting CLOCK_REALTIME directly through a new interface/clockid (which would be duplicative).

thanks
-john

maintainer
#7 lore raw

Re: [PATCH 2/3] ptp: add a software clock based on clock_monotonic_raw

Quoted 10 lines · john stultz
Quoted 3 lines · Richard Cochran

I do think a software only PHC will make it easier for people to get started with the new interface. I have been carrying along such a patch privately for my own testing.

Consistency is but a hobgoblin... :)

But seriously, do forgive me if I misunderstood your earlier patches with this respect. I thought it was just exporting CLOCK_REALTIME directly through a new interface/clockid (which would be duplicative).

You are right, I was doing that, but the purpose was for testing.

I am not sure where Torben is going with his idea. In order to figure out meaningful clock adjustments, you need the clock's timestamps on the PTP packet tx/rx events. Implementing an internal clock correction with no connection to the network stack might still be interesting, but I think having the timestamps is much more useful.

Let's wait and see what Torben says once he come back from travel.

Thanks,

Richard

author
#8 lore raw

Re: [PATCH 2/3] ptp: add a software clock based on clock_monotonic_raw

Quoted 12 lines · Richard Cochran
Quoted 10 lines · john stultz
Quoted 3 lines · Richard Cochran

I do think a software only PHC will make it easier for people to get started with the new interface. I have been carrying along such a patch privately for my own testing.

Consistency is but a hobgoblin... :)

But seriously, do forgive me if I misunderstood your earlier patches with this respect. I thought it was just exporting CLOCK_REALTIME directly through a new interface/clockid (which would be duplicative).

Quoted 7 lines

You are right, I was doing that, but the purpose was for testing.

I am not sure where Torben is going with his idea. In order to figure out meaningful clock adjustments, you need the clock's timestamps on the PTP packet tx/rx events. Implementing an internal clock correction with no connection to the network stack might still be interesting, but I think having the timestamps is much more useful.

I am planning to enable the networking stack to timestamp using arbitrary clock id.
But that means adding an ioctl. So there is going to be a lot of critical review, and questions asked.

On the audio lists, we have a guy now claiming that software ptp would confuse the whole h/w ptp infrastructure. His main agenda seems to be to prevent a software only ptp/avb implementatation.
I cant imagine how a slave clock can confuse a master clock. And emission of audio stream packets does not need to be accurate to the nanosecond.

I am a bit confused now, because i initially thought, i could quote that guy to prove that an avb master clock might not necessarily be suitable to become CLOCK_REALTIME.

I am still assuming this. But i dont really have proof. This might block this.

Quoted 6 lines

Let's wait and see what Torben says once he come back from travel.

Thanks,

Richard

Signature · 1 line
torben Hohn
#9 lore raw

RE: [PATCH 2/3] ptp: add a software clock based on clock_monotonic_raw

Torben,

Quoted 3 lines · torbenh

On the audio lists, we have a guy now claiming that software ptp would confuse the whole h/w ptp infrastructure. His main agenda seems to be to prevent a software only ptp/avb implementatation.

could you please post a link to that discussion?
Thanks,
Christian ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

author
#10 lore raw

Re: [PATCH 2/3] ptp: add a software clock based on clock_monotonic_raw

Quoted 8 lines · Christian Riesch

Torben,

Quoted 3 lines · torbenh

On the audio lists, we have a guy now claiming that software ptp would confuse the whole h/w ptp infrastructure. His main agenda seems to be to prevent a software only ptp/avb implementatation.

could you please post a link to that discussion?

duncan started somewhat like this:
http://article.gmane.org/gmane.comp.audio.jackit/23606
http://article.gmane.org/gmane.comp.audio.jackit/23612

then it seems that he somehow turned his head:
http://www.mail-archive.com/[email protected]/msg11765.html

maybe we have a communication problem, with the definition of "play" i only want to be able to generate an RTP stream on my computer.

the actual conversion from packets to analog signal would be happening on a networked soundcard. the goal is to achieve low latency in the range of 2-3ms ...

maybe he interprets playing the rtp stream, as converting the rtp packets to analog audio.
this obviously wouldnt work with software ptp, because we would need nanoseconds accuracy of the clock.

but to just create an rtp stream, where a 2ms buffer doesnt underflow, just requires a clock accuracy of 500us.

all in all this discussion might be a bit confusing.

Quoted 2 lines

Thanks,
Christian

Signature · 1 line
torben Hohn
#11 lore raw

Re: [PATCH 2/3] ptp: add a software clock based on clock_monotonic_raw

In reply to torbenh

Torben,

Quoted 3 lines · torbenh

On the audio lists, we have a guy now claiming that software ptp would confuse the whole h/w ptp infrastructure. His main agenda seems to be to prevent a software only ptp/avb implementatation.

could you please post a link to that discussion?
Thanks,
Christian

maintainer
#12 lore raw

Re: [PATCH 2/3] ptp: add a software clock based on clock_monotonic_raw

In reply to Torben Hohn

drivers/ptp/Kconfig config PTP_1588_CLOCK_IXP46X · line 47

Quoted 5 lines · Torben Hohn
drivers/ptp/Kconfig +5 -0
+config PTP_1588_CLOCK_SOFTWARE
+	tristate "software PTP clock"
+	depends on PTP_1588_CLOCK
+	help
+	  This driver adds a software PTP clock. 

As John said, this needs a longer description. You can look back at my V6 as an example.

https://lkml.org/lkml/2010/9/23/220

Quoted 1 line

+static int ptp_ixp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)

Once again, please rename.

Better yet, why not just use the V6 example instead? If we are going to have a testing driver, then I would want the simulated ancillary code as well.

drivers/ptp/ptp_software.c line 185

Quoted 5 lines
drivers/ptp/ptp_software.c new file +5 -0
+
+static struct ptp_clock_info ptp_ixp_caps = {
+	.owner		= THIS_MODULE,
+	.name		= "software timer",
+	.max_adj	= 66666655,

You should calculate the actual limit of adjustment and use it here.

Thanks,

Richard

author
#13 lore raw

Re: [PATCH 2/3] ptp: add a software clock based on clock_monotonic_raw

Quoted 10 lines · Richard Cochran

drivers/ptp/Kconfig config PTP_1588_CLOCK_IXP46X · line 47

Quoted 5 lines · Torben Hohn
drivers/ptp/Kconfig +5 -0
+config PTP_1588_CLOCK_SOFTWARE
+	tristate "software PTP clock"
+	depends on PTP_1588_CLOCK
+	help
+	  This driver adds a software PTP clock. 

As John said, this needs a longer description. You can look back at my V6 as an example.

Quoted 5 lines

https://lkml.org/lkml/2010/9/23/220

Quoted 1 line

+static int ptp_ixp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)

Once again, please rename.

i was planning to rename it.
i just posted my patches early on because i had found the permission problem, and thought the software clock might be useful to play around with the whole framework.
iE without the software clock, i wouldnt have found the actual problem, because i dont have the right h/w.

Quoted 4 lines

Better yet, why not just use the V6 example instead? If we are going to have a testing driver, then I would want the simulated ancillary code as well.

well... your example code messes with clock_realtime.
i was planning to emit real timed events, not just some simulation. but i dont completely understand this part of the code yet.

Quoted 8 lines

drivers/ptp/ptp_software.c line 185

Quoted 6 lines
drivers/ptp/ptp_software.c new file +5 -0
+
+static struct ptp_clock_info ptp_ixp_caps = {
+	.owner		= THIS_MODULE,
+	.name		= "software timer",
+	.max_adj	= 66666655,

You should calculate the actual limit of adjustment and use it here.

yeah. i posted it too early...
gonna fix it in the next iteration.

Signature · 1 line
torben Hohn
maintainer
#14 lore raw

Re: [PATCH 2/3] ptp: add a software clock based on clock_monotonic_raw

Quoted 7 lines · torbenh
Quoted 4 lines · Richard Cochran

Better yet, why not just use the V6 example instead? If we are going to have a testing driver, then I would want the simulated ancillary code as well.

well... your example code messes with clock_realtime.

But could you take the file and replace the CLOCK_REALTIME code with your SW implemented offset/frequency corrections?

And, just keep my code for simulating the ancillary stuff as is.

Quoted 2 lines

i was planning to emit real timed events, not just some simulation. but i dont completely understand this part of the code yet.

??? (None of my PHC patches implement any user timers.)

I am not sure where you are going with the AVB clock idea, but it will be fun to find out.

Thanks,

Richard

#15 lore raw

PATCH 3/3 Check for write permission on FD based posix-clocks

In reply to Torben Hohn

pc_clock_settime() and pc_clock_adjtime() did not check whether the fd was opened in write mode.

It was possible to set a clock, when we only had read permissions.

for completeness, we would also need to check for Read permissions on the read operations. but that would be a bit paranoid, probably.

Cc Richard Cochran <[email protected]>
Cc John Stultz <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 kernel/time/posix-clock.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
kernel/time/posix-clock.c +12 -2
index 04498cb..25028dd 100644
@@ -287,11 +287,16 @@ static int pc_clock_adjtime(clockid_t id, struct timex *tx)
 	if (err)
 		return err;
 
+	if ((cd.fp->f_mode & FMODE_WRITE) == 0) {
+		err = -EACCES;
+		goto out;
+	}
+
 	if (cd.clk->ops.clock_adjtime)
 		err = cd.clk->ops.clock_adjtime(cd.clk, tx);
 	else
 		err = -EOPNOTSUPP;
-
+out:
 	put_clock_desc(&cd);
 
 	return err;
@@ -344,11 +349,16 @@ static int pc_clock_settime(clockid_t id, const struct timespec *ts)
 	if (err)
 		return err;
 
+	if ((cd.fp->f_mode & FMODE_WRITE) == 0) {
+		err = -EACCES;
+		goto out;
+	}
+
 	if (cd.clk->ops.clock_settime)
 		err = cd.clk->ops.clock_settime(cd.clk, ts);
 	else
 		err = -EOPNOTSUPP;
-
+out:
 	put_clock_desc(&cd);
 
 	return err;
Signature · 1 line
1.7.2.3
maintainer
#16 lore raw

Re: [PATCH 3/3] Check for write permission on FD based posix-clocks

Quoted 8 lines · Torben Hohn

pc_clock_settime() and pc_clock_adjtime() did not check whether the fd was opened in write mode.

It was possible to set a clock, when we only had read permissions.

for completeness, we would also need to check for Read permissions on the read operations. but that would be a bit paranoid, probably.

I have no objection to this form of clock access control, but I would like to get agreement about it from the list.

kernel/time/posix-clock.c static int pc_clock_adjtime(clockid_t id, struct timex *tx) · line 291

Quoted 10 lines
kernel/time/posix-clock.c +2 -0
index 04498cb..25028dd 100644
@@ -287,11 +287,16 @@ static int pc_clock_adjtime(clockid_t id, struct timex *tx)
 	if (err)
 		return err;
 
+	if ((cd.fp->f_mode & FMODE_WRITE) == 0) {
+		err = -EACCES;

Looks like clock_settime and adjtimex are supposed to return EPERM in this case.

Thanks,

Richard

#17 lore raw

Re: [PATCH 3/3] Check for write permission on FD based posix-clocks

Quoted 8 lines · On Friday 04 March 2011 08:22:39 Richard Cochran wrote:
Quoted 8 lines
kernel/time/posix-clock.c +0 -0
index 04498cb..25028dd 100644
@@ -287,11 +287,16 @@ static int pc_clock_adjtime(clockid_t id, struct timex *tx)
      if (err)
              return err;
 
Quoted 6 lines

kernel/time/posix-clock.c static int pc_clock_adjtime(clockid_t id, struct timex *tx) · line 291

Quoted 2 lines
kernel/time/posix-clock.c +2 -0
+     if ((cd.fp->f_mode & FMODE_WRITE) == 0) {
+             err = -EACCES;

Looks like clock_settime and adjtimex are supposed to return EPERM in this case.

I think both choices are correct:

EACCESS often refers to the file permissions of an inode or the mode of an open file. EPERM usually means that an operation can only be performed by the owner of an object or by root. So clock_settime and adjtimex should return EPERM and pc_clock_adjtime should return EACCESS.

Arnd

author
#18 lore raw

Re: [PATCH 3/3] Check for write permission on FD based posix-clocks

In reply to Richard Cochran
Quoted 21 lines · Richard Cochran
Quoted 8 lines · Torben Hohn

pc_clock_settime() and pc_clock_adjtime() did not check whether the fd was opened in write mode.

It was possible to set a clock, when we only had read permissions.

for completeness, we would also need to check for Read permissions on the read operations. but that would be a bit paranoid, probably.

I have no objection to this form of clock access control, but I would like to get agreement about it from the list.

Quoted 8 lines
kernel/time/posix-clock.c +0 -0
index 04498cb..25028dd 100644
@@ -287,11 +287,16 @@ static int pc_clock_adjtime(clockid_t id, struct timex *tx)
 	if (err)
 		return err;
 
Quoted 5 lines

kernel/time/posix-clock.c static int pc_clock_adjtime(clockid_t id, struct timex *tx) · line 291

Quoted 2 lines
kernel/time/posix-clock.c +2 -0
+	if ((cd.fp->f_mode & FMODE_WRITE) == 0) {
+		err = -EACCES;

Looks like clock_settime and adjtimex are supposed to return EPERM in this case.

well... this is more similar to calling write(2) on an fd not opened with FMODE_WRITE...

ssize_t vfs_writev(struct file *file, const struct iovec __user *vec,
unsigned long vlen, loff_t *pos)

{
	if (!(file->f_mode & FMODE_WRITE))
		return -EBADF;
	if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
		return -EINVAL;

	return do_readv_writev(WRITE, file, vec, vlen, pos);
}

so probably -EBADF is also a candidate :)
however, since the syscall is not really fd based, EPERM is probably closer to the current man page.

Signature · 1 line
torben Hohn
#19 lore raw

Re: [PATCH 3/3] Check for write permission on FD based posix-clocks

In reply to Richard Cochran
Quoted 4 lines · Richard Cochran
Quoted 3 lines · Torben Hohn

pc_clock_settime() and pc_clock_adjtime() did not check whether the fd was opened in write mode.

Quoted 8 lines
Quoted 5 lines

It was possible to set a clock, when we only had read permissions.

for completeness, we would also need to check for Read permissions on the read operations. but that would be a bit paranoid, probably.

I have no objection to this form of clock access control, but I would like to get agreement about it from the list.

Acked-by-me

Quoted 8 lines
Quoted 8 lines
kernel/time/posix-clock.c +0 -0
index 04498cb..25028dd 100644
@@ -287,11 +287,16 @@ static int pc_clock_adjtime(clockid_t id, struct timex *tx)
 	if (err)
 		return err;
 
Quoted 5 lines

kernel/time/posix-clock.c static int pc_clock_adjtime(clockid_t id, struct timex *tx) · line 291

Quoted 2 lines
kernel/time/posix-clock.c +2 -0
+	if ((cd.fp->f_mode & FMODE_WRITE) == 0) {
+		err = -EACCES;

Looks like clock_settime and adjtimex are supposed to return EPERM in this case.

As Arnd already said -EACCES is sensible for file permission checks while -EPERM means that you have no permission at all.

Thanks,

tglx

maintainer
#20 lore raw

Re: [PATCH 3/3] Check for write permission on FD based posix-clocks

Quoted 2 lines · Thomas Gleixner

As Arnd already said -EACCES is sensible for file permission checks while -EPERM means that you have no permission at all.

Okay, so you will accept Torben's patch as is, into timers/core?

Thanks,

Richard

#21 lore raw

Re: [PATCH 3/3] Check for write permission on FD based posix-clocks

Quoted 5 lines · Richard Cochran
Quoted 2 lines · Thomas Gleixner

As Arnd already said -EACCES is sensible for file permission checks while -EPERM means that you have no permission at all.

Okay, so you will accept Torben's patch as is, into timers/core?

If there are no further objections, I'll pick it up.

Thanks,

tglx

#22 lore raw

[tip:timers/core] posix-clocks: Check write permissions in posix syscalls

In reply to Torben Hohn
Commit-ID:  6e6823d17b157f185be09f4c70181299f9273f0b
Gitweb:     http://git.kernel.org/tip/6e6823d17b157f185be09f4c70181299f9273f0b
Author:     Torben Hohn <[email protected]>
AuthorDate: Thu, 3 Mar 2011 18:26:14 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Sat, 12 Mar 2011 21:27:07 +0100

posix-clocks: Check write permissions in posix syscalls

pc_clock_settime() and pc_clock_adjtime() do not check whether the fd was opened in write mode, so a clock can be set with a read only fd.

[ tglx: We deliberately do not return -EPERM as we want this to be
distingushable from the capability based permission check ]

LKML-Reference: <[email protected]>
Cc: Richard Cochran <[email protected]>
Cc: John Stultz <[email protected]>
Cc: Thomas Gleixner <[email protected]>

---
 kernel/time/posix-clock.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
kernel/time/posix-clock.c +12 -2
index 04498cb..25028dd 100644
@@ -287,11 +287,16 @@ static int pc_clock_adjtime(clockid_t id, struct timex *tx)
 	if (err)
 		return err;
 
+	if ((cd.fp->f_mode & FMODE_WRITE) == 0) {
+		err = -EACCES;
+		goto out;
+	}
+
 	if (cd.clk->ops.clock_adjtime)
 		err = cd.clk->ops.clock_adjtime(cd.clk, tx);
 	else
 		err = -EOPNOTSUPP;
-
+out:
 	put_clock_desc(&cd);
 
 	return err;
@@ -344,11 +349,16 @@ static int pc_clock_settime(clockid_t id, const struct timespec *ts)
 	if (err)
 		return err;
 
+	if ((cd.fp->f_mode & FMODE_WRITE) == 0) {
+		err = -EACCES;
+		goto out;
+	}
+
 	if (cd.clk->ops.clock_settime)
 		err = cd.clk->ops.clock_settime(cd.clk, ts);
 	else
 		err = -EOPNOTSUPP;
-
+out:
 	put_clock_desc(&cd);
 
 	return err;
maintainer
#23 lore raw
In reply to Torben Hohn
Quoted 8 lines · Torben Hohn

patches 1 and 3 apply on top of tip:core/timer

patch 2 also requires Richards ptp v12 1/4 for the ptp class. modulo a small conflict in drivers/ptp/Makefile and Kconfig. because i had added his ixp driver, which the software clock is based on.

Richards Patchset didnt apply to tip:core/timer as is. which branch is it based on ?

I can apply them to

db1c1cce4a653dcbe6949c72ae7b9f42cab1b929

near the head of timers/core in

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git

I guess the newer CLOCK_BOOTTIME commits cause a conflict. I will rebase once again to fix that.

Thanks,
Richard

maintainer
#24 lore raw
Quoted 6 lines · Richard Cochran
Quoted 2 lines · Torben Hohn

Richards Patchset didnt apply to tip:core/timer as is. which branch is it based on ?

I can apply them to

Quoted 8 lines
   db1c1cce4a653dcbe6949c72ae7b9f42cab1b929

near the head of timers/core in

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git

I guess the newer CLOCK_BOOTTIME commits cause a conflict. I will rebase once again to fix that.

Torben, I don't understand why you couldn't apply V12 to the timers/core head. It works fine for me...

Richard

a0e5fef2 ptp: Added a clock driver for the National Semiconductor PHYTER. a992fe1f ptp: Added a clock driver for the IXP46x.
d57a0b3e ptp: Added a clock that uses the eTSEC found on the MPC85xx. 3f341675 ptp: Added a brand new class driver for ptp clocks. 5cd10e79 hrtimer: Update base[CLOCK_BOOTTIME].offset correctly 7fdd7f89 timers: Export CLOCK_BOOTTIME via the posix timers interface 70a08cca timers: Add CLOCK_BOOTTIME hrtimer base
314ac371 time: Extend get_xtime_and_monotonic_offset() to also return sleep abb3a4ea time: Introduce get_monotonic_boottime and ktime_get_boottime e06383db hrtimers: extend hrtimer base code to handle more then 2 clockids db1c1cce ntp: Remove redundant and incorrect parameter check 22b7fcda mn10300: Switch do_timer() to xtimer_update()
0606f422 posix clocks: Introduce dynamic clocks