public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: YongSu Yoo <yongsuyoo0215@gmail.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	linma@zju.edu.cn, v4bel@theori.io, linux-media@vger.kernel.org
Subject: [PATCH AUTOSEL 6.1 19/57] media: dvb_ca_en50221: fix a size write bug
Date: Thu, 25 May 2023 14:35:29 -0400	[thread overview]
Message-ID: <20230525183607.1793983-19-sashal@kernel.org> (raw)
In-Reply-To: <20230525183607.1793983-1-sashal@kernel.org>

From: YongSu Yoo <yongsuyoo0215@gmail.com>

[ Upstream commit a4315e5be7020aac9b24a8151caf4bb85224cd0e ]

The function of "dvb_ca_en50221_write_data" at source/drivers/media
/dvb-core/dvb_ca_en50221.c is used for two cases.
The first case is for writing APDU data in the function of
"dvb_ca_en50221_io_write" at source/drivers/media/dvb-core/
dvb_ca_en50221.c.
The second case is for writing the host link buf size on the
Command Register in the function of "dvb_ca_en50221_link_init"
at source/drivers/media/dvb-core/dvb_ca_en50221.c.
In the second case, there exists a bug like following.
In the function of the "dvb_ca_en50221_link_init",
after a TV host calculates the host link buf_size,
the TV host writes the calculated host link buf_size on the
Size Register.
Accroding to the en50221 Spec (the page 60 of
https://dvb.org/wp-content/uploads/2020/02/En50221.V1.pdf),
before this writing operation, the "SW(CMDREG_SW)" flag in the
Command Register should be set. We can see this setting operation
in the function of the "dvb_ca_en50221_link_init" like below.
...
	if ((ret = ca->pub->write_cam_control(ca->pub, slot,
CTRLIF_COMMAND, IRQEN | CMDREG_SW)) != 0)
		return ret;
...
But, after that, the real writing operation is implemented using
the function of the "dvb_ca_en50221_write_data" in the function of
"dvb_ca_en50221_link_init", and the "dvb_ca_en50221_write_data"
includes the function of "ca->pub->write_cam_control",
and the function of the "ca->pub->write_cam_control" in the
function of the "dvb_ca_en50221_wrte_data" does not include
"CMDREG_SW" flag like below.
...
	if ((status = ca->pub->write_cam_control(ca->pub, slot,
CTRLIF_COMMAND, IRQEN | CMDREG_HC)) != 0)
...
In the above source code, we can see only the "IRQEN | CMDREG_HC",
but we cannot see the "CMDREG_SW".
The "CMDREG_SW" flag which was set in the function of the
"dvb_ca_en50221_link_init" was rollbacked by the follwoing function
of the "dvb_ca_en50221_write_data".
This is a bug. and this bug causes that the calculated host link buf_size
is not properly written in the CI module.
Through this patch, we fix this bug.

Link: https://lore.kernel.org/linux-media/20220818125027.1131-1-yongsuyoo0215@gmail.com
Signed-off-by: YongSu Yoo <yongsuyoo0215@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/media/dvb-core/dvb_ca_en50221.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c
index c2d2792227f86..b6ca29dfb184a 100644
--- a/drivers/media/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb-core/dvb_ca_en50221.c
@@ -187,7 +187,7 @@ static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private *ca);
 static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot,
 				    u8 *ebuf, int ecount);
 static int dvb_ca_en50221_write_data(struct dvb_ca_private *ca, int slot,
-				     u8 *ebuf, int ecount);
+				     u8 *ebuf, int ecount, int size_write_flag);
 
 /**
  * findstr - Safely find needle in haystack.
@@ -370,7 +370,7 @@ static int dvb_ca_en50221_link_init(struct dvb_ca_private *ca, int slot)
 	ret = dvb_ca_en50221_wait_if_status(ca, slot, STATUSREG_FR, HZ / 10);
 	if (ret)
 		return ret;
-	ret = dvb_ca_en50221_write_data(ca, slot, buf, 2);
+	ret = dvb_ca_en50221_write_data(ca, slot, buf, 2, CMDREG_SW);
 	if (ret != 2)
 		return -EIO;
 	ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN);
@@ -778,11 +778,13 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot,
  * @buf: The data in this buffer is treated as a complete link-level packet to
  *	 be written.
  * @bytes_write: Size of ebuf.
+ * @size_write_flag: A flag on Command Register which says whether the link size
+ * information will be writen or not.
  *
  * return: Number of bytes written, or < 0 on error.
  */
 static int dvb_ca_en50221_write_data(struct dvb_ca_private *ca, int slot,
-				     u8 *buf, int bytes_write)
+				     u8 *buf, int bytes_write, int size_write_flag)
 {
 	struct dvb_ca_slot *sl = &ca->slot_info[slot];
 	int status;
@@ -817,7 +819,7 @@ static int dvb_ca_en50221_write_data(struct dvb_ca_private *ca, int slot,
 
 	/* OK, set HC bit */
 	status = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND,
-					    IRQEN | CMDREG_HC);
+					    IRQEN | CMDREG_HC | size_write_flag);
 	if (status)
 		goto exit;
 
@@ -1508,7 +1510,7 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
 
 			mutex_lock(&sl->slot_lock);
 			status = dvb_ca_en50221_write_data(ca, slot, fragbuf,
-							   fraglen + 2);
+							   fraglen + 2, 0);
 			mutex_unlock(&sl->slot_lock);
 			if (status == (fraglen + 2)) {
 				written = 1;
-- 
2.39.2


  parent reply	other threads:[~2023-05-25 18:41 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25 18:35 [PATCH AUTOSEL 6.1 01/57] nvme-pci: add NVME_QUIRK_BOGUS_NID for HS-SSD-FUTURE 2048G Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 02/57] nvme-pci: add quirk for missing secondary temperature thresholds Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 03/57] ASoC: amd: yc: Add DMI entry to support System76 Pangolin 12 Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 04/57] ASoC: dwc: limit the number of overrun messages Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 05/57] selftests/ftrace: Improve integration with kselftest runner Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 06/57] um: harddog: fix modular build Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 07/57] xfrm: Check if_id in inbound policy/secpath match Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 08/57] ASoC: dt-bindings: Adjust #sound-dai-cells on TI's single-DAI codecs Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 09/57] ALSA: hda/realtek: Add quirks for ASUS GU604V and GU603V Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 10/57] ASoC: ssm2602: Add workaround for playback distortions Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 11/57] media: dvb_demux: fix a bug for the continuity counter Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 12/57] media: dvb-usb: az6027: fix three null-ptr-deref in az6027_i2c_xfer() Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 13/57] media: dvb-usb-v2: ec168: fix null-ptr-deref in ec168_i2c_xfer() Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 14/57] media: dvb-usb-v2: ce6230: fix null-ptr-deref in ce6230_i2c_master_xfer() Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 15/57] media: dvb-usb-v2: rtl28xxu: fix null-ptr-deref in rtl28xxu_i2c_xfer Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 16/57] media: dvb-usb: digitv: fix null-ptr-deref in digitv_i2c_xfer() Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 17/57] media: dvb-usb: dw2102: fix uninit-value in su3000_read_mac_address Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 18/57] media: netup_unidvb: fix irq init by register it at the end of probe Sasha Levin
2023-05-25 18:35 ` Sasha Levin [this message]
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 20/57] media: ttusb-dec: fix memory leak in ttusb_dec_exit_dvb() Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 21/57] media: mn88443x: fix !CONFIG_OF error by drop of_match_ptr from ID table Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 22/57] media: dvb-core: Fix use-after-free due on race condition at dvb_net Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 23/57] media: dvb-core: Fix use-after-free due to race at dvb_register_device() Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 24/57] media: dvb-core: Fix kernel WARNING for blocking operation in wait_event*() Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 25/57] media: dvb-core: Fix use-after-free due to race condition at dvb_ca_en50221 Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 26/57] ASoC: SOF: debug: conditionally bump runtime_pm counter on exceptions Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 27/57] ASoC: SOF: pcm: fix pm_runtime imbalance in error handling Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 28/57] ASoC: SOF: sof-client-probes: " Sasha Levin
2023-06-16 19:24   ` Pavel Machek
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 29/57] ASoC: SOF: pm: save io region state in case of errors in resume Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 30/57] tipc: add tipc_bearer_min_mtu to calculate min mtu Sasha Levin
2023-06-16 19:27   ` Pavel Machek
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 31/57] s390/pkey: zeroize key blobs Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 32/57] s390/topology: honour nr_cpu_ids when adding CPUs Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 33/57] ACPI: resource: Add IRQ override quirk for LG UltraPC 17U70P Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 34/57] wifi: rtl8xxxu: fix authentication timeout due to incorrect RCR value Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 35/57] ARM: dts: stm32: add pin map for CAN controller on stm32f7 Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 36/57] ARM: dts: stm32: add CAN support on stm32f746 Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 37/57] arm64/mm: mark private VM_FAULT_X defines as vm_fault_t Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 38/57] arm64: vdso: Pass (void *) to virt_to_page() Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 39/57] wifi: mac80211: simplify chanctx allocation Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 40/57] wifi: mac80211: consider reserved chanctx for mindef Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 41/57] wifi: mac80211: recalc chanctx mindef before assigning Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 42/57] wifi: iwlwifi: mvm: Add locking to the rate read flow Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 43/57] scsi: core: Decrease scsi_device's iorequest_cnt if dispatch failed Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 44/57] wifi: b43: fix incorrect __packed annotation Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 45/57] net: wwan: t7xx: Ensure init is completed before system sleep Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 46/57] netfilter: conntrack: define variables exp_nat_nla_policy and any_addr with CONFIG_NF_NAT Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 47/57] nvme-multipath: don't call blk_mark_disk_dead in nvme_mpath_remove_disk Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 48/57] nvme: do not let the user delete a ctrl before a complete initialization Sasha Levin
2023-05-25 18:35 ` [PATCH AUTOSEL 6.1 49/57] ALSA: oss: avoid missing-prototype warnings Sasha Levin
2023-05-25 18:36 ` [PATCH AUTOSEL 6.1 50/57] drm/msm: Be more shouty if per-process pgtables aren't working Sasha Levin
2023-05-25 18:36 ` [PATCH AUTOSEL 6.1 51/57] atm: hide unused procfs functions Sasha Levin
2023-05-25 18:36 ` [PATCH AUTOSEL 6.1 52/57] mdio_bus: unhide mdio_bus_init prototype Sasha Levin
2023-05-25 18:36 ` [PATCH AUTOSEL 6.1 53/57] ceph: silence smatch warning in reconnect_caps_cb() Sasha Levin
2023-05-25 18:36 ` [PATCH AUTOSEL 6.1 54/57] drm/amdgpu: skip disabling fence driver src_irqs when device is unplugged Sasha Levin
2023-05-25 18:36 ` [PATCH AUTOSEL 6.1 55/57] ublk: fix AB-BA lockdep warning Sasha Levin
2023-05-25 18:36 ` [PATCH AUTOSEL 6.1 56/57] nvme-pci: Add quirk for Teamgroup MP33 SSD Sasha Levin
2023-05-25 18:36 ` [PATCH AUTOSEL 6.1 57/57] block: Deny writable memory mapping if block is read-only Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230525183607.1793983-19-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=linma@zju.edu.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=v4bel@theori.io \
    --cc=yongsuyoo0215@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox