<feed xmlns='http://www.w3.org/2005/Atom'>
<title>user/sven/linux.git/drivers/ptp, branch v5.4.76</title>
<subtitle>Linux Kernel
</subtitle>
<id>https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v5.4.76</id>
<link rel='self' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v5.4.76'/>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/'/>
<updated>2020-01-23T07:22:51Z</updated>
<entry>
<title>ptp: free ptp device pin descriptors properly</title>
<updated>2020-01-23T07:22:51Z</updated>
<author>
<name>Vladis Dronov</name>
<email>vdronov@redhat.com</email>
</author>
<published>2020-01-13T13:00:09Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=4fd16cfcc3ae28cf42c67941fd529600f21bec39'/>
<id>urn:sha1:4fd16cfcc3ae28cf42c67941fd529600f21bec39</id>
<content type='text'>
[ Upstream commit 75718584cb3c64e6269109d4d54f888ac5a5fd15 ]

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: 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-01-04T18:18:48Z</updated>
<author>
<name>Vladis Dronov</name>
<email>vdronov@redhat.com</email>
</author>
<published>2019-12-27T02:26:27Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=bfa2e0cd3dfda64fde43c3dca3aeba298d2fe7ad'/>
<id>urn:sha1:bfa2e0cd3dfda64fde43c3dca3aeba298d2fe7ad</id>
<content type='text'>
[ Upstream commit a33121e5487b424339636b25c35d3a180eaa5f5e ]

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: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>ptp: Introduce strict checking of external time stamp options.</title>
<updated>2019-11-15T20:48:32Z</updated>
<author>
<name>Richard Cochran</name>
<email>richardcochran@gmail.com</email>
</author>
<published>2019-11-14T18:45:02Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=6138e687c7b679da08c0feb55a88f448f7890c07'/>
<id>urn:sha1:6138e687c7b679da08c0feb55a88f448f7890c07</id>
<content type='text'>
User space may request time stamps on rising edges, falling edges, or
both.  However, the particular mode may or may not be supported in the
hardware or in the driver.  This patch adds a "strict" flag that tells
drivers to ensure that the requested mode will be honored.

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 requests to enable time stamping of external signals.</title>
<updated>2019-11-15T20:48:32Z</updated>
<author>
<name>Richard Cochran</name>
<email>richardcochran@gmail.com</email>
</author>
<published>2019-11-14T18:44:55Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=cd734d54e67990eebfc3106dc39047c1141d4197'/>
<id>urn:sha1:cd734d54e67990eebfc3106dc39047c1141d4197</id>
<content type='text'>
Commit 415606588c61 ("PTP: introduce new versions of IOCTLs")
introduced a new external time stamp ioctl that validates the flags.
This patch extends the validation to ensure that at least one rising
or falling edge flag is set when enabling external time stamps.

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: fix typo of "mechanism" in Kconfig help text</title>
<updated>2019-10-07T18:55:46Z</updated>
<author>
<name>Antonio Borneo</name>
<email>antonio.borneo@st.com</email>
</author>
<published>2019-10-07T15:43:02Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=503c9addef613c872679e24fc8a78f3febeb5a08'/>
<id>urn:sha1:503c9addef613c872679e24fc8a78f3febeb5a08</id>
<content type='text'>
Fix typo s/mechansim/mechanism/

Signed-off-by: Antonio Borneo &lt;antonio.borneo@st.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>ptp_qoriq: Initialize the registers' spinlock before calling ptp_qoriq_settime</title>
<updated>2019-10-02T16:20:38Z</updated>
<author>
<name>Vladimir Oltean</name>
<email>olteanv@gmail.com</email>
</author>
<published>2019-10-01T19:07:01Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=db34a4714c013b644eec2de0ec81b1f0373b8b93'/>
<id>urn:sha1:db34a4714c013b644eec2de0ec81b1f0373b8b93</id>
<content type='text'>
Because ptp_qoriq_settime is being called prior to spin_lock_init, the
following stack trace can be seen at driver probe time:

[    2.269117] the code is fine but needs lockdep annotation.
[    2.274569] turning off the locking correctness validator.
[    2.280027] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.3.0-rc7-01478-g01eaa67a4797 #263
[    2.288073] Hardware name: Freescale LS1021A
[    2.292337] [&lt;c0313cb4&gt;] (unwind_backtrace) from [&lt;c030e11c&gt;] (show_stack+0x10/0x14)
[    2.300045] [&lt;c030e11c&gt;] (show_stack) from [&lt;c1219440&gt;] (dump_stack+0xcc/0xf8)
[    2.307235] [&lt;c1219440&gt;] (dump_stack) from [&lt;c03b9b44&gt;] (register_lock_class+0x730/0x73c)
[    2.315372] [&lt;c03b9b44&gt;] (register_lock_class) from [&lt;c03b6190&gt;] (__lock_acquire+0x78/0x270c)
[    2.323856] [&lt;c03b6190&gt;] (__lock_acquire) from [&lt;c03b90cc&gt;] (lock_acquire+0xe0/0x22c)
[    2.331649] [&lt;c03b90cc&gt;] (lock_acquire) from [&lt;c123c310&gt;] (_raw_spin_lock_irqsave+0x54/0x68)
[    2.340048] [&lt;c123c310&gt;] (_raw_spin_lock_irqsave) from [&lt;c0e73fe4&gt;] (ptp_qoriq_settime+0x38/0x80)
[    2.348878] [&lt;c0e73fe4&gt;] (ptp_qoriq_settime) from [&lt;c0e746d4&gt;] (ptp_qoriq_init+0x1f8/0x484)
[    2.357189] [&lt;c0e746d4&gt;] (ptp_qoriq_init) from [&lt;c0e74aac&gt;] (ptp_qoriq_probe+0xd0/0x184)
[    2.365243] [&lt;c0e74aac&gt;] (ptp_qoriq_probe) from [&lt;c0b0a07c&gt;] (platform_drv_probe+0x48/0x9c)
[    2.373555] [&lt;c0b0a07c&gt;] (platform_drv_probe) from [&lt;c0b07a14&gt;] (really_probe+0x1c4/0x400)
[    2.381779] [&lt;c0b07a14&gt;] (really_probe) from [&lt;c0b07e28&gt;] (driver_probe_device+0x78/0x1b8)
[    2.390003] [&lt;c0b07e28&gt;] (driver_probe_device) from [&lt;c0b081d0&gt;] (device_driver_attach+0x58/0x60)
[    2.398832] [&lt;c0b081d0&gt;] (device_driver_attach) from [&lt;c0b082d4&gt;] (__driver_attach+0xfc/0x160)
[    2.407402] [&lt;c0b082d4&gt;] (__driver_attach) from [&lt;c0b05a84&gt;] (bus_for_each_dev+0x68/0xb4)
[    2.415539] [&lt;c0b05a84&gt;] (bus_for_each_dev) from [&lt;c0b06b68&gt;] (bus_add_driver+0x104/0x20c)
[    2.423763] [&lt;c0b06b68&gt;] (bus_add_driver) from [&lt;c0b0909c&gt;] (driver_register+0x78/0x10c)
[    2.431815] [&lt;c0b0909c&gt;] (driver_register) from [&lt;c030313c&gt;] (do_one_initcall+0x8c/0x3ac)
[    2.439954] [&lt;c030313c&gt;] (do_one_initcall) from [&lt;c1f013f4&gt;] (kernel_init_freeable+0x468/0x548)
[    2.448610] [&lt;c1f013f4&gt;] (kernel_init_freeable) from [&lt;c12344d8&gt;] (kernel_init+0x8/0x10c)
[    2.456745] [&lt;c12344d8&gt;] (kernel_init) from [&lt;c03010b4&gt;] (ret_from_fork+0x14/0x20)
[    2.464273] Exception stack(0xea89ffb0 to 0xea89fff8)
[    2.469297] ffa0:                                     00000000 00000000 00000000 00000000
[    2.477432] ffc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    2.485566] ffe0: 00000000 00000000 00000000 00000000 00000013 00000000

Fixes: ff54571a747b ("ptp_qoriq: convert to use ptp_qoriq_init/free")
Signed-off-by: Vladimir Oltean &lt;olteanv@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>ptp: correctly disable flags on old ioctls</title>
<updated>2019-09-27T18:25:32Z</updated>
<author>
<name>Jacob Keller</name>
<email>jacob.e.keller@intel.com</email>
</author>
<published>2019-09-26T02:28:19Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=2df4de1681767df900e15e34195bbf7dc1b23e06'/>
<id>urn:sha1:2df4de1681767df900e15e34195bbf7dc1b23e06</id>
<content type='text'>
Commit 415606588c61 ("PTP: introduce new versions of IOCTLs",
2019-09-13) introduced new versions of the PTP ioctls which actually
validate that the flags are acceptable values.

As part of this, it cleared the flags value using a bitwise
and+negation, in an attempt to prevent the old ioctl from accidentally
enabling new features.

This is incorrect for a couple of reasons. First, it results in
accidentally preventing previously working flags on the request ioctl.
By clearing the "valid" flags, we now no longer allow setting the
enable, rising edge, or falling edge flags.

Second, if we add new additional flags in the future, they must not be
set by the old ioctl. (Since the flag wasn't checked before, we could
potentially break userspace programs which sent garbage flag data.

The correct way to resolve this is to check for and clear all but the
originally valid flags.

Create defines indicating which flags are correctly checked and
interpreted by the original ioctls. Use these to clear any bits which
will not be correctly interpreted by the original ioctls.

In the future, new flags must be added to the VALID_FLAGS macros, but
*not* to the V1_VALID_FLAGS macros. In this way, new features may be
exposed over the v2 ioctls, but without breaking previous userspace
which happened to not clear the flags value properly. The old ioctl will
continue to behave the same way, while the new ioctl gains the benefit
of using the flags fields.

Cc: Richard Cochran &lt;richardcochran@gmail.com&gt;
Cc: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Cc: David S. Miller &lt;davem@davemloft.net&gt;
Cc: Christopher Hall &lt;christopher.s.hall@intel.com&gt;
Signed-off-by: Jacob Keller &lt;jacob.e.keller@intel.com&gt;
Acked-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 new versions of IOCTLs</title>
<updated>2019-09-13T13:57:02Z</updated>
<author>
<name>Felipe Balbi</name>
<email>felipe.balbi@linux.intel.com</email>
</author>
<published>2019-09-11T06:16:21Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=415606588c61230b7b4f0118fc2d64a0c1c4d102'/>
<id>urn:sha1:415606588c61230b7b4f0118fc2d64a0c1c4d102</id>
<content type='text'>
The current version of the IOCTL have a small problem which prevents us
from extending the API by making use of reserved fields. In these new
IOCTLs, we are now making sure that flags and rsv fields are zero which
will allow us to extend the API in the future.

Reviewed-by: Richard Cochran &lt;richardcochran@gmail.com&gt;
Signed-off-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>ptp: ptp_dte: remove redundant dev_err message</title>
<updated>2019-07-25T18:37:40Z</updated>
<author>
<name>Ding Xiang</name>
<email>dingxiang@cmss.chinamobile.com</email>
</author>
<published>2019-07-23T08:54:05Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=37f7c66f4560b154cfa7a8d8f1902e222e38adba'/>
<id>urn:sha1:37f7c66f4560b154cfa7a8d8f1902e222e38adba</id>
<content type='text'>
devm_ioremap_resource already contains error message, so remove
the redundant dev_err message

Signed-off-by: Ding Xiang &lt;dingxiang@cmss.chinamobile.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>ptp: add QorIQ PTP support for DPAA2</title>
<updated>2019-06-15T20:43:06Z</updated>
<author>
<name>Yangbo Lu</name>
<email>yangbo.lu@nxp.com</email>
</author>
<published>2019-06-14T10:40:50Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=8099d7ca6e7b76282fef7565877f5c8f02f8ef4f'/>
<id>urn:sha1:8099d7ca6e7b76282fef7565877f5c8f02f8ef4f</id>
<content type='text'>
This patch is to add QorIQ PTP support for DPAA2.
Although dpaa2-ptp.c driver is a fsl_mc_driver which
is using MC APIs for register accessing, it's same
IP block with eTSEC/DPAA/ENETC 1588 timer. We will
convert to reuse ptp_qoriq driver by using register
ioremap and dropping related MC APIs.
Also allow to compile ptp_qoriq with COMPILE_TEST.

Signed-off-by: Yangbo Lu &lt;yangbo.lu@nxp.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
</feed>
