Commit 44b93e82 authored by Thomas Weißschuh's avatar Thomas Weißschuh Committed by Pu Lehui
Browse files

ptp: Ensure info->enable callback is always set

stable inclusion
from stable-v6.6.78
commit 81846070cba17125a866e8023c01d3465b153339
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IBPLLG
CVE: CVE-2025-21814

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=81846070cba1



--------------------------------

commit fd53aa40e65f518453115b6f56183b0c201db26b upstream.

The ioctl and sysfs handlers unconditionally call the ->enable callback.
Not all drivers implement that callback, leading to NULL dereferences.
Example of affected drivers: ptp_s390.c, ptp_vclock.c and ptp_mock.c.

Instead use a dummy callback if no better was specified by the driver.

Fixes: d94ba80e ("ptp: Added a brand new class driver for ptp clocks.")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarThomas Weißschuh <linux@weissschuh.net>
Acked-by: default avatarRichard Cochran <richardcochran@gmail.com>
Reviewed-by: default avatarMichal Swiatkowski <michal.swiatkowski@linux.intel.com>
Link: https://patch.msgid.link/20250123-ptp-enable-v1-1-b015834d3a47@weissschuh.net


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarPu Lehui <pulehui@huawei.com>
parent 9d22d5b7
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -189,6 +189,11 @@ static int ptp_getcycles64(struct ptp_clock_info *info, struct timespec64 *ts)
		return info->gettime64(info, ts);
}

static int ptp_enable(struct ptp_clock_info *ptp, struct ptp_clock_request *request, int on)
{
	return -EOPNOTSUPP;
}

static void ptp_aux_kworker(struct kthread_work *work)
{
	struct ptp_clock *ptp = container_of(work, struct ptp_clock,
@@ -251,6 +256,9 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
			ptp->info->getcrosscycles = ptp->info->getcrosststamp;
	}

	if (!ptp->info->enable)
		ptp->info->enable = ptp_enable;

	if (ptp->info->do_aux_work) {
		kthread_init_delayed_work(&ptp->aux_work, ptp_aux_kworker);
		ptp->kworker = kthread_create_worker(0, "ptp%d", ptp->index);