<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/drivers/ptp/ptp_clock.c, branch linux-4.4.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.4.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.4.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2020-05-20T06:11:41Z</updated>
<entry>
<title>ptp: free ptp device pin descriptors properly</title>
<updated>2020-05-20T06:11:41Z</updated>
<author>
<name>Vladis Dronov</name>
</author>
<published>2020-01-13T13:00:09Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a9acf25d6c38acbf428130d092c7048f4510ae82'/>
<id>urn:sha1:a9acf25d6c38acbf428130d092c7048f4510ae82</id>
<content type='text'>
commit 75718584cb3c64e6269109d4d54f888ac5a5fd15 upstream.

There is a bug in ptp_clock_unregister(), where ptp_cleanup_pin_groups()
first frees ptp-&gt;pin_{,dev_}attr, but then posix_clock_unregister() needs
them to destroy a related sysfs device.

These functions can not be just swapped, as posix_clock_unregister() frees
ptp which is needed in the ptp_cleanup_pin_groups(). Fix this by calling
ptp_cleanup_pin_groups() in ptp_clock_release(), right before ptp is freed.

This makes this patch fix an UAF bug in a patch which fixes an UAF bug.

Reported-by: Antti Laakso &lt;antti.laakso@intel.com&gt;
Fixes: a33121e5487b ("ptp: fix the race between the release of ptp_clock and cdev")
Link: https://lore.kernel.org/netdev/3d2bd09735dbdaf003585ca376b7c1e5b69a19bd.camel@intel.com/
Signed-off-by: Vladis Dronov &lt;vdronov@redhat.com&gt;
Acked-by: Richard Cochran &lt;richardcochran@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Ben Hutchings &lt;ben.hutchings@codethink.co.uk&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>ptp: fix the race between the release of ptp_clock and cdev</title>
<updated>2020-05-20T06:11:41Z</updated>
<author>
<name>Vladis Dronov</name>
</author>
<published>2019-12-27T02:26:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=6f5e3bb7879ee1eb71c6c3cbaaffbb0da6cd7d57'/>
<id>urn:sha1:6f5e3bb7879ee1eb71c6c3cbaaffbb0da6cd7d57</id>
<content type='text'>
commit a33121e5487b424339636b25c35d3a180eaa5f5e upstream.

In a case when a ptp chardev (like /dev/ptp0) is open but an underlying
device is removed, closing this file leads to a race. This reproduces
easily in a kvm virtual machine:

ts# cat openptp0.c
int main() { ... fp = fopen("/dev/ptp0", "r"); ... sleep(10); }
ts# uname -r
5.5.0-rc3-46cf053e
ts# cat /proc/cmdline
... slub_debug=FZP
ts# modprobe ptp_kvm
ts# ./openptp0 &amp;
[1] 670
opened /dev/ptp0, sleeping 10s...
ts# rmmod ptp_kvm
ts# ls /dev/ptp*
ls: cannot access '/dev/ptp*': No such file or directory
ts# ...woken up
[   48.010809] general protection fault: 0000 [#1] SMP
[   48.012502] CPU: 6 PID: 658 Comm: openptp0 Not tainted 5.5.0-rc3-46cf053e #25
[   48.014624] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), ...
[   48.016270] RIP: 0010:module_put.part.0+0x7/0x80
[   48.017939] RSP: 0018:ffffb3850073be00 EFLAGS: 00010202
[   48.018339] RAX: 000000006b6b6b6b RBX: 6b6b6b6b6b6b6b6b RCX: ffff89a476c00ad0
[   48.018936] RDX: fffff65a08d3ea08 RSI: 0000000000000247 RDI: 6b6b6b6b6b6b6b6b
[   48.019470] ...                                              ^^^ a slub poison
[   48.023854] Call Trace:
[   48.024050]  __fput+0x21f/0x240
[   48.024288]  task_work_run+0x79/0x90
[   48.024555]  do_exit+0x2af/0xab0
[   48.024799]  ? vfs_write+0x16a/0x190
[   48.025082]  do_group_exit+0x35/0x90
[   48.025387]  __x64_sys_exit_group+0xf/0x10
[   48.025737]  do_syscall_64+0x3d/0x130
[   48.026056]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[   48.026479] RIP: 0033:0x7f53b12082f6
[   48.026792] ...
[   48.030945] Modules linked in: ptp i6300esb watchdog [last unloaded: ptp_kvm]
[   48.045001] Fixing recursive fault but reboot is needed!

This happens in:

static void __fput(struct file *file)
{   ...
    if (file-&gt;f_op-&gt;release)
        file-&gt;f_op-&gt;release(inode, file); &lt;&lt;&lt; cdev is kfree'd here
    if (unlikely(S_ISCHR(inode-&gt;i_mode) &amp;&amp; inode-&gt;i_cdev != NULL &amp;&amp;
             !(mode &amp; FMODE_PATH))) {
        cdev_put(inode-&gt;i_cdev); &lt;&lt;&lt; cdev fields are accessed here

Namely:

__fput()
  posix_clock_release()
    kref_put(&amp;clk-&gt;kref, delete_clock) &lt;&lt;&lt; the last reference
      delete_clock()
        delete_ptp_clock()
          kfree(ptp) &lt;&lt;&lt; cdev is embedded in ptp
  cdev_put
    module_put(p-&gt;owner) &lt;&lt;&lt; *p is kfree'd, bang!

Here cdev is embedded in posix_clock which is embedded in ptp_clock.
The race happens because ptp_clock's lifetime is controlled by two
refcounts: kref and cdev.kobj in posix_clock. This is wrong.

Make ptp_clock's sysfs device a parent of cdev with cdev_device_add()
created especially for such cases. This way the parent device with its
ptp_clock is not released until all references to the cdev are released.
This adds a requirement that an initialized but not exposed struct
device should be provided to posix_clock_register() by a caller instead
of a simple dev_t.

This approach was adopted from the commit 72139dfa2464 ("watchdog: Fix
the race between the release of watchdog_core_data and cdev"). See
details of the implementation in the commit 233ed09d7fda ("chardev: add
helper function to register char devs with a struct device").

Link: https://lore.kernel.org/linux-fsdevel/20191125125342.6189-1-vdronov@redhat.com/T/#u
Analyzed-by: Stephen Johnston &lt;sjohnsto@redhat.com&gt;
Analyzed-by: Vern Lovejoy &lt;vlovejoy@redhat.com&gt;
Signed-off-by: Vladis Dronov &lt;vdronov@redhat.com&gt;
Acked-by: Richard Cochran &lt;richardcochran@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Ben Hutchings &lt;ben.hutchings@codethink.co.uk&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>ptp: Fix pass zero to ERR_PTR() in ptp_clock_register</title>
<updated>2020-05-20T06:11:40Z</updated>
<author>
<name>YueHaibing</name>
</author>
<published>2018-11-23T01:54:55Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=6091936487a95791e24019ad949d11c661700205'/>
<id>urn:sha1:6091936487a95791e24019ad949d11c661700205</id>
<content type='text'>
commit aea0a897af9e44c258e8ab9296fad417f1bc063a upstream.

Fix smatch warning:

drivers/ptp/ptp_clock.c:298 ptp_clock_register() warn:
 passing zero to 'ERR_PTR'

'err' should be set while device_create_with_groups and
pps_register_source fails

Fixes: 85a66e550195 ("ptp: create "pins" together with the rest of attributes")
Signed-off-by: YueHaibing &lt;yuehaibing@huawei.com&gt;
Acked-by: Richard Cochran &lt;richardcochran@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Ben Hutchings &lt;ben.hutchings@codethink.co.uk&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>ptp: create "pins" together with the rest of attributes</title>
<updated>2020-05-20T06:11:40Z</updated>
<author>
<name>Dmitry Torokhov</name>
</author>
<published>2017-02-14T18:23:34Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e5a654c9935cf48f6b1913e0e1aea81945e1585b'/>
<id>urn:sha1:e5a654c9935cf48f6b1913e0e1aea81945e1585b</id>
<content type='text'>
commit 85a66e55019583da1e0f18706b7a8281c9f6de5b upstream.

Let's switch to using device_create_with_groups(), which will allow us to
create "pins" attribute group together with the rest of ptp device
attributes, and before userspace gets notified about ptp device creation.

Signed-off-by: Dmitry Torokhov &lt;dmitry.torokhov@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
[bwh: Backported to 4.9: adjust context]
Signed-off-by: Ben Hutchings &lt;ben.hutchings@codethink.co.uk&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>ptp: do not explicitly set drvdata in ptp_clock_register()</title>
<updated>2020-05-20T06:11:39Z</updated>
<author>
<name>Dmitry Torokhov</name>
</author>
<published>2017-02-14T18:23:31Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f212dbd2b2e84184fd32ac3962d4a3bd770a0db3'/>
<id>urn:sha1:f212dbd2b2e84184fd32ac3962d4a3bd770a0db3</id>
<content type='text'>
commit 882f312dc0751c973db26478f07f082c584d16aa upstream.

We do not need explicitly call dev_set_drvdata(), as it is done for us by
device_create().

Acked-by: Richard Cochran &lt;richardcochran@gmail.com&gt;
Signed-off-by: Dmitry Torokhov &lt;dmitry.torokhov@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
Signed-off-by: Ben Hutchings &lt;ben.hutchings@codethink.co.uk&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>time: Change posix clocks ops interfaces to use timespec64</title>
<updated>2018-03-24T09:58:40Z</updated>
<author>
<name>Deepa Dinamani</name>
</author>
<published>2017-03-26T19:04:13Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=de54723bc15a3354215cd6ae76591ee4c0af96d2'/>
<id>urn:sha1:de54723bc15a3354215cd6ae76591ee4c0af96d2</id>
<content type='text'>
[ Upstream commit d340266e19ddb70dbd608f9deedcfb35fdb9d419 ]

struct timespec is not y2038 safe on 32 bit machines.

The posix clocks apis use struct timespec directly and through struct
itimerspec.

Replace the posix clock interfaces to use struct timespec64 and struct
itimerspec64 instead.  Also fix up their implementations accordingly.

Note that the clock_getres() interface has also been changed to use
timespec64 even though this particular interface is not affected by the
y2038 problem. This helps verification for internal kernel code for y2038
readiness by getting rid of time_t/ timeval/ timespec.

Signed-off-by: Deepa Dinamani &lt;deepa.kernel@gmail.com&gt;
Cc: arnd@arndb.de
Cc: y2038@lists.linaro.org
Cc: netdev@vger.kernel.org
Cc: Richard Cochran &lt;richardcochran@gmail.com&gt;
Cc: john.stultz@linaro.org
Link: http://lkml.kernel.org/r/1490555058-4603-3-git-send-email-deepa.kernel@gmail.com
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Sasha Levin &lt;alexander.levin@microsoft.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>ptp: remove 32 bit get/set methods.</title>
<updated>2015-03-31T16:01:19Z</updated>
<author>
<name>Richard Cochran</name>
</author>
<published>2015-03-29T21:12:13Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=ed7c6317bc599502e1fdc7f5f95cb9a5550360a4'/>
<id>urn:sha1:ed7c6317bc599502e1fdc7f5f95cb9a5550360a4</id>
<content type='text'>
All of the PHC drivers have been converted to the new methods.  This patch
converts the three remaining callers within the core code and removes the
older methods for good.  As a result, the core PHC code is ready for the
year 2038.  However, some of the PHC drivers are not quite ready yet.

Signed-off-by: Richard Cochran &lt;richardcochran@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>ptp: use the 64 bit get/set time methods for the posix clock.</title>
<updated>2015-03-31T16:01:16Z</updated>
<author>
<name>Richard Cochran</name>
</author>
<published>2015-03-29T21:11:53Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d7d38f5bd7bece539a6cbb59fc8121f29f63fbdb'/>
<id>urn:sha1:d7d38f5bd7bece539a6cbb59fc8121f29f63fbdb</id>
<content type='text'>
This patch changes the posix clock code to prefer the new methods
whenever they are implemented by the PHC drivers.

Signed-off-by: Richard Cochran &lt;richardcochran@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>ptp: validate the requested frequency adjustment.</title>
<updated>2014-04-28T17:28:43Z</updated>
<author>
<name>Richard Cochran</name>
</author>
<published>2014-04-27T13:01:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d39a743511cdb80884b4b9cd506fe84b6b08e66e'/>
<id>urn:sha1:d39a743511cdb80884b4b9cd506fe84b6b08e66e</id>
<content type='text'>
PTP Hardware Clock drivers specify a maximum frequency adjustment that
their clocks can accommodate. Normally, user space programs will want to
respect the advertised limits. However, no kernel or driver code checks
that the dialed frequency offset is within the bounds, and out of range
values can lead to surprising results.

This patch fixes the issue by rejecting bad values.

Signed-off-by: Richard Cochran &lt;richardcochran@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>ptp: introduce programmable pins.</title>
<updated>2014-03-21T18:21:13Z</updated>
<author>
<name>Richard Cochran</name>
</author>
<published>2014-03-20T21:21:52Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=6092315dfdec5185881605d15a0e200d6e90eb66'/>
<id>urn:sha1:6092315dfdec5185881605d15a0e200d6e90eb66</id>
<content type='text'>
This patch adds a pair of new ioctls to the PTP Hardware Clock device
interface. Using the ioctls, user space programs can query each pin to
find out its current function and also reprogram a different function
if desired.

Signed-off-by: Richard Cochran &lt;richardcochran@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
</feed>
