Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3925169pxj; Mon, 21 Jun 2021 09:30:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9DJO9O1q0MGVFzWnLP1j+Mml5avlMJFkK2KrtdIOvdwKnFSLNQ4tHcNNx0LrE1uJyUhST X-Received: by 2002:a92:c991:: with SMTP id y17mr19129488iln.125.1624293008568; Mon, 21 Jun 2021 09:30:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624293008; cv=none; d=google.com; s=arc-20160816; b=lc2bl+Z/fgdh793D2rC5OWMLAtEtWZYTgDUzV552WNrAyMjBXnwAqCWeYopx2qf/8I b9owLAl+3ccUcxw65ovhytUhfE2haBF6J3k/qFo1S5uBu3TS8U21CoQ36CJ77Qs6LJys IMpXexGahj+7rEWGnB71xfxSZ14AadCqfqlPA5iFewQYE/mlvZiS+IY49n913OalJtTh yBinCWwrae+FCRtae/Bi1wq9aSbX5j/7NEvCZhAp41nwIwgHGtPjkQIRCPeKVq5vCWja /d2IpMg8i5Wro9E9mU6Pii+CGzu25JA5VPPnsp719kL8lnJPO8E5rjOL+rvBxr7U6Dpy w9hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pn1QeGJyp4/KTKmkfnwW/4fRpltIQOtMrv6qDY5NsfE=; b=WLbmoUTlJEJ0msFZpORHP2fRkJ0ewY/3AwCseaytjxElBuyvcietl/EtlnDPhGa745 6+YVkGJGMJWUhMgGw+g+ZrxjmoSgnKoXsSHyTPZuWBu+772qjFWR1NvqGGbx7OIuYj04 sx3P1cy4geg6r2k3O2+2KOvHLAEtq7BNzkolF+9LO83twDEEgpDa3tsmbdFmueZ4Tobe MsXJo4mFAtgS8jBqnXPVZNu8CABN22J3FSWZc6lpIFyJmFEIJTwGlYseh5kq9pDsQGwm hA5rrMpuHU4iJIRNi0CP0hElb+Vr6QsjqNu1Qbe9wANqoYP6l9mK85KzUKVD3F3wWn2v NBsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VY27cdmX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s15si19019955jaj.103.2021.06.21.09.29.55; Mon, 21 Jun 2021 09:30:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VY27cdmX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232452AbhFUQbo (ORCPT + 99 others); Mon, 21 Jun 2021 12:31:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:48302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230357AbhFUQ1z (ORCPT ); Mon, 21 Jun 2021 12:27:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 32B4A613EB; Mon, 21 Jun 2021 16:23:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292584; bh=mylEgiwtRkEGqF1+6jEvX8z7gkdV3zCUBmhzGEtZKFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VY27cdmXPw9/WP2I9wj+4AhN1scZJwC7U5Q0jG8hF2aaFMi+hWOOgOxwfsKnE/jVz RhspOyg4yZFi0/VYU8AHYktj9Om+k3J5kkvPba/JV7sIjI0voa+EP98iAh7DjaR4j2 GFTlYbkhK5MHqjCXG2F1MpoWZYHFdYnbsT2u4iF8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jakub Kicinski , Richard Cochran , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 055/146] ptp: improve max_adj check against unreasonable values Date: Mon, 21 Jun 2021 18:14:45 +0200 Message-Id: <20210621154913.983787719@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154911.244649123@linuxfoundation.org> References: <20210621154911.244649123@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jakub Kicinski [ Upstream commit 475b92f932168a78da8109acd10bfb7578b8f2bb ] Scaled PPM conversion to PPB may (on 64bit systems) result in a value larger than s32 can hold (freq/scaled_ppm is a long). This means the kernel will not correctly reject unreasonably high ->freq values (e.g. > 4294967295ppb, 281474976645 scaled PPM). The conversion is equivalent to a division by ~66 (65.536), so the value of ppb is always smaller than ppm, but not small enough to assume narrowing the type from long -> s32 is okay. Note that reasonable user space (e.g. ptp4l) will not use such high values, anyway, 4289046510ppb ~= 4.3x, so the fix is somewhat pedantic. Fixes: d39a743511cd ("ptp: validate the requested frequency adjustment.") Fixes: d94ba80ebbea ("ptp: Added a brand new class driver for ptp clocks.") Signed-off-by: Jakub Kicinski Acked-by: Richard Cochran Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/ptp/ptp_clock.c | 6 +++--- include/linux/ptp_clock_kernel.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index 03a246e60fd9..21c4c34c52d8 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -63,7 +63,7 @@ static void enqueue_external_timestamp(struct timestamp_event_queue *queue, spin_unlock_irqrestore(&queue->lock, flags); } -s32 scaled_ppm_to_ppb(long ppm) +long scaled_ppm_to_ppb(long ppm) { /* * The 'freq' field in the 'struct timex' is in parts per @@ -80,7 +80,7 @@ s32 scaled_ppm_to_ppb(long ppm) s64 ppb = 1 + ppm; ppb *= 125; ppb >>= 13; - return (s32) ppb; + return (long) ppb; } EXPORT_SYMBOL(scaled_ppm_to_ppb); @@ -138,7 +138,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct __kernel_timex *tx) delta = ktime_to_ns(kt); err = ops->adjtime(ops, delta); } else if (tx->modes & ADJ_FREQUENCY) { - s32 ppb = scaled_ppm_to_ppb(tx->freq); + long ppb = scaled_ppm_to_ppb(tx->freq); if (ppb > ops->max_adj || ppb < -ops->max_adj) return -ERANGE; if (ops->adjfine) diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h index d3e8ba5c7125..6d6b42143eff 100644 --- a/include/linux/ptp_clock_kernel.h +++ b/include/linux/ptp_clock_kernel.h @@ -222,7 +222,7 @@ extern int ptp_clock_index(struct ptp_clock *ptp); * @ppm: Parts per million, but with a 16 bit binary fractional field */ -extern s32 scaled_ppm_to_ppb(long ppm); +extern long scaled_ppm_to_ppb(long ppm); /** * ptp_find_pin() - obtain the pin index of a given auxiliary function -- 2.30.2