From patchwork Mon May 21 21:47:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Krufky X-Patchwork-Id: 11369 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1SWaTX-0005O3-Du for patchwork@linuxtv.org; Mon, 21 May 2012 23:49:11 +0200 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.75/mailfrontend-2) with esmtp for id 1SWaTW-00008G-IV; Mon, 21 May 2012 23:49:11 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759325Ab2EUVtI (ORCPT ); Mon, 21 May 2012 17:49:08 -0400 Received: from mail-qa0-f49.google.com ([209.85.216.49]:40688 "EHLO mail-qa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754260Ab2EUVtG (ORCPT ); Mon, 21 May 2012 17:49:06 -0400 Received: by qabj40 with SMTP id j40so3003846qab.1 for ; Mon, 21 May 2012 14:49:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=OVnY/vAA/aQ/AF7vWBYbP4NE+kCtwW3TA7HG72I4BCk=; b=S9UIzql0uWNaapo/ANHkHpXoU142l+Fv90RdZC8xAgEG62uLXtjBYalWFN3jPqdta4 RPBeqD0+MVdv2BHPxvJhYZ6jmJLYVkm/UDmBQARGsWkRR672hR74A4jeFxABPeNIRyT0 Z0SH5CL2sVVu0TwhXnkkTlHzZ+uZB/aeqPRshl4zRH5buWvWAZwgOXprGZjeGIQtaZvB WI/sHEO9Se9YNpm+m5a9vKqsiTPWPvCxvisN56yn12Ztu+2AxkzF/3HVTckFuvW6XoyN D8Bh4PkXdAC2gF+xrBrPH7qhyd18JQAPDUMuciXK7mvUhWxjNtqivuRTCmn6aS95nc/i /Zyg== Received: by 10.224.181.137 with SMTP id by9mr9830442qab.9.1337636946070; Mon, 21 May 2012 14:49:06 -0700 (PDT) Received: from outlands.localdomain6 (cpe-67-247-37-142.nyc.res.rr.com. [67.247.37.142]) by mx.google.com with ESMTPS id i7sm41341263qae.20.2012.05.21.14.49.04 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 21 May 2012 14:49:05 -0700 (PDT) From: Michael Krufky To: linux-media@vger.kernel.org Cc: mchehab@infradead.org, Michael Krufky Subject: [PATCH] DVB: improve handling of TS packets containing a raised TEI bit Date: Mon, 21 May 2012 17:47:15 -0400 Message-Id: <1337636835-6580-1-git-send-email-mkrufky@linuxtv.org> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQkCItEc6FYw/mfqHn5Y9gTBBNTdGSF7/KoVYczZQnwMpfEjuWuFDq18pdaaHWSi7MKqsyey Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2012.5.21.213625 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, DATE_TZ_NA 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __MIME_TEXT_ONLY 0, __MULTIPLE_RCPTS_CC_X2 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS ' When the TEI bit is raised, we should not trust any of the contents of the packet in question, including but not limited to its PID number. Considering that we don't trust the PID number of this packet, we should not proceed to check the packet counter (if dvb_demux_tscheck is set). We should expect to see at least one discontinuity after a bad packet is received, so any time a TEI is detected, a following TS packet counter mismatch is to be expected. There is no real reason to ever allow bad packets to pass through the kernel demux, other than for purposes of attempting error correction via software or statistical information. However, since we have always passed these bad packets though the demux, we should not change this default behavior. Without altering module options, this patch merely prevents the TS packet counter check on packets containing a raised TEI. If module option dvb_demux_feed_err_pkts is set to 0, the kernel demux will drop these error packets entirely, preventing any possibility of corruption caused by userspace programs that are expecting valid data. Signed-off-by: Michael Krufky --- drivers/media/dvb/dvb-core/dvb_demux.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/media/dvb/dvb-core/dvb_demux.c b/drivers/media/dvb/dvb-core/dvb_demux.c index d82469f..17cb81f 100644 --- a/drivers/media/dvb/dvb-core/dvb_demux.c +++ b/drivers/media/dvb/dvb-core/dvb_demux.c @@ -50,6 +50,11 @@ module_param(dvb_demux_speedcheck, int, 0644); MODULE_PARM_DESC(dvb_demux_speedcheck, "enable transport stream speed check"); +static int dvb_demux_feed_err_pkts = 1; +module_param(dvb_demux_feed_err_pkts, int, 0644); +MODULE_PARM_DESC(dvb_demux_feed_err_pkts, + "when set to 0, drop packets with the TEI bit set (1 by default)"); + #define dprintk_tscheck(x...) do { \ if (dvb_demux_tscheck && printk_ratelimit()) \ printk(x); \ @@ -426,14 +431,18 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf) }; }; + if (buf[1] & 0x80) { + dprintk_tscheck("TEI detected. " + "PID=0x%x data1=0x%x\n", + pid, buf[1]); + /* data in this packet cant be trusted - drop it unless + * module option dvb_demux_feed_err_pkts is set */ + if (!dvb_demux_feed_err_pkts) + return; + } else /* if TEI bit is set, pid may be wrong- skip pkt counter */ if (demux->cnt_storage && dvb_demux_tscheck) { /* check pkt counter */ if (pid < MAX_PID) { - if (buf[1] & 0x80) - dprintk_tscheck("TEI detected. " - "PID=0x%x data1=0x%x\n", - pid, buf[1]); - if ((buf[3] & 0xf) != demux->cnt_storage[pid]) dprintk_tscheck("TS packet counter mismatch. " "PID=0x%x expected 0x%x "