Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6556553ybx; Mon, 11 Nov 2019 10:54:18 -0800 (PST) X-Google-Smtp-Source: APXvYqzWUcGwwzaUjjIS1/SJTsIsw+NFAAnyLRgM3Q/MeA+LarNkX2pchNv7F6aIg04NaPvEbxgk X-Received: by 2002:a50:c3c5:: with SMTP id i5mr28140845edf.137.1573498458353; Mon, 11 Nov 2019 10:54:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498458; cv=none; d=google.com; s=arc-20160816; b=fusJUV76V26Dapv5AoCKXA6l9o6RxsKYE1jywjwD5+PoFnNwNyzOIYCKNdWCpH1Qpf nGPn05KwHhOqbDN0yqxwoX0eeGdNIbk2hsM89KVhB92rsiknnIT641swh72FtJpW4gtW UBGCZubCTHgPSizhrht6KMf4nzhMgZtFzH8L/r+IYBkKnFZ0zuPjELi/Nzo6tGrytq5J tBsmp10qW/xRfDhqIpBg4lB0j2I4NhqvTa0uw+LfxItXNyX5t96KjctLn5xFzGTlN7CQ S2CJQGuGyC/HEV/snnqbhS8UFSZikBsw/UITpSN7KsLnEAJBKb1kf1u2pdR8TsSUHx3T /F7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PWnxw0ZgRilbymOkfDEAUnG0h+549MILphzwkHQjU8U=; b=T3ghgc0qUXlz/JNLaKvQROqm5+SOIqSSKm7yB0GVivStKcEnRgNUs9VsOOahFkVrHz qRFXNI7fHRUOKH00fImJIu+42me0nnV69eZsNW3MiCjdgQf+tbQU/Ccvhrg7kCTK5baU RxzfawZ82eedR1N8WJlnIPgzwVIk1BhIrTF/fyAWHlCpI6bQJQNQpuHOIOj1ILJp/COC zpZRMLT1hCBEUrZbc+SeUyGxA190tS/nIViFKj+266eLxSbh/7VzeSc0ijZg2gY3gTxe Bu2LMpTENOeZd4DiBwJQLZfYj/jp+CK0I5Gc8D0gm4vlDrLWTj0Yh3LIQeDDQsKT1VWP bX6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=octoxiIH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o10si13747216edj.316.2019.11.11.10.53.54; Mon, 11 Nov 2019 10:54:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=octoxiIH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730417AbfKKSvS (ORCPT + 99 others); Mon, 11 Nov 2019 13:51:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:45440 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730263AbfKKSvR (ORCPT ); Mon, 11 Nov 2019 13:51:17 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7FA8D222C1; Mon, 11 Nov 2019 18:51:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498277; bh=6lgpsgg7uVgYl5DWn9S8ulDSED75HDu61aSomNLuS7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=octoxiIHkIdGxSlqejmULtG6fgFQSdo1AJ0aZoBGwd+F+Erc4iorripbFbZEGWh19 WHo2LQfQi7qdONeLrkAJEG+76/Bs8xHh/Oja1KnpAZnrX5XjYDXXy0+gVCdnKwcERT EBqnhoV27zg56BLTZGvWmIyvcbJvamYrF4gBHL+o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephane Grosjean , Marc Kleine-Budde Subject: [PATCH 5.3 075/193] can: peak_usb: fix a potential out-of-sync while decoding packets Date: Mon, 11 Nov 2019 19:27:37 +0100 Message-Id: <20191111181506.659173609@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181459.850623879@linuxfoundation.org> References: <20191111181459.850623879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stephane Grosjean commit de280f403f2996679e2607384980703710576fed upstream. When decoding a buffer received from PCAN-USB, the first timestamp read in a packet is a 16-bit coded time base, and the next ones are an 8-bit offset to this base, regardless of the type of packet read. This patch corrects a potential loss of synchronization by using a timestamp index read from the buffer, rather than an index of received data packets, to determine on the sizeof the timestamp to be read from the packet being decoded. Signed-off-by: Stephane Grosjean Fixes: 46be265d3388 ("can: usb: PEAK-System Technik PCAN-USB specific part") Cc: linux-stable Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/usb/peak_usb/pcan_usb.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) --- a/drivers/net/can/usb/peak_usb/pcan_usb.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c @@ -100,7 +100,7 @@ struct pcan_usb_msg_context { u8 *end; u8 rec_cnt; u8 rec_idx; - u8 rec_data_idx; + u8 rec_ts_idx; struct net_device *netdev; struct pcan_usb *pdev; }; @@ -547,10 +547,15 @@ static int pcan_usb_decode_status(struct mc->ptr += PCAN_USB_CMD_ARGS; if (status_len & PCAN_USB_STATUSLEN_TIMESTAMP) { - int err = pcan_usb_decode_ts(mc, !mc->rec_idx); + int err = pcan_usb_decode_ts(mc, !mc->rec_ts_idx); if (err) return err; + + /* Next packet in the buffer will have a timestamp on a single + * byte + */ + mc->rec_ts_idx++; } switch (f) { @@ -632,10 +637,13 @@ static int pcan_usb_decode_data(struct p cf->can_dlc = get_can_dlc(rec_len); - /* first data packet timestamp is a word */ - if (pcan_usb_decode_ts(mc, !mc->rec_data_idx)) + /* Only first packet timestamp is a word */ + if (pcan_usb_decode_ts(mc, !mc->rec_ts_idx)) goto decode_failed; + /* Next packet in the buffer will have a timestamp on a single byte */ + mc->rec_ts_idx++; + /* read data */ memset(cf->data, 0x0, sizeof(cf->data)); if (status_len & PCAN_USB_STATUSLEN_RTR) { @@ -688,7 +696,6 @@ static int pcan_usb_decode_msg(struct pe /* handle normal can frames here */ } else { err = pcan_usb_decode_data(&mc, sl); - mc.rec_data_idx++; } }