Blob Blame History Raw
From bf0cd60b7e33cf221fbe1114e4acb2c828b0af0d Mon Sep 17 00:00:00 2001
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Date: Fri, 4 Mar 2022 21:56:47 +0900
Subject: [PATCH] ALSA: firewire-lib: fix uninitialized flag for AV/C deferred transaction
Git-commit: bf0cd60b7e33cf221fbe1114e4acb2c828b0af0d
Patch-mainline: v5.18-rc1
References: git-fixes

AV/C deferred transaction was supported at a commit 00a7bb81c20f ("ALSA:
Firewire-lib: Add support for deferred transaction") while 'deferrable'
flag can be uninitialized for non-control/notify AV/C transactions.
UBSAN reports it:

Kernel: ================================================================================
Kernel: UBSAN: invalid-load in /build/linux-aa0B4d/linux-5.15.0/sound/firewire/fcp.c:363:9
Kernel: load of value 158 is not a valid value for type '_Bool'
Kernel: CPU: 3 PID: 182227 Comm: irq/35-firewire Tainted: P           OE     5.15.0-18-generic #18-Ubuntu
Kernel: Hardware name: Gigabyte Technology Co., Ltd. AX370-Gaming 5/AX370-Gaming 5, BIOS F42b 08/01/2019
Kernel: Call Trace:
Kernel: <IRQ>
Kernel: show_stack+0x52/0x58
Kernel: dump_stack_lvl+0x4a/0x5f
Kernel: dump_stack+0x10/0x12
Kernel: ubsan_epilogue+0x9/0x45
Kernel: __ubsan_handle_load_invalid_value.cold+0x44/0x49
Kernel: fcp_response.part.0.cold+0x1a/0x2b [snd_firewire_lib]
Kernel: fcp_response+0x28/0x30 [snd_firewire_lib]
Kernel: fw_core_handle_request+0x230/0x3d0 [firewire_core]
Kernel: handle_ar_packet+0x1d9/0x200 [firewire_ohci]
Kernel: ? handle_ar_packet+0x1d9/0x200 [firewire_ohci]
Kernel: ? transmit_complete_callback+0x9f/0x120 [firewire_core]
Kernel: ar_context_tasklet+0xa8/0x2e0 [firewire_ohci]
Kernel: tasklet_action_common.constprop.0+0xea/0xf0
Kernel: tasklet_action+0x22/0x30
Kernel: __do_softirq+0xd9/0x2e3
Kernel: ? irq_finalize_oneshot.part.0+0xf0/0xf0
Kernel: do_softirq+0x75/0xa0
Kernel: </IRQ>
Kernel: <TASK>
Kernel: __local_bh_enable_ip+0x50/0x60
Kernel: irq_forced_thread_fn+0x7e/0x90
Kernel: irq_thread+0xba/0x190
Kernel: ? irq_thread_fn+0x60/0x60
Kernel: kthread+0x11e/0x140
Kernel: ? irq_thread_check_affinity+0xf0/0xf0
Kernel: ? set_kthread_struct+0x50/0x50
Kernel: ret_from_fork+0x22/0x30
Kernel: </TASK>

This commit fixes the bug. The bug has no disadvantage for the non-
control/notify AV/C transactions since the flag has an effect for AV/C
response with INTERIM (0x0f) status which is not used for the transactions
in AV/C general specification.

Fixes: 00a7bb81c20f ("ALSA: firewire-lib: Add support for deferred transaction")
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Link: https://lore.kernel.org/r/20220304125647.78430-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Iwai <tiwai@suse.de>

---
 sound/firewire/fcp.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/sound/firewire/fcp.c b/sound/firewire/fcp.c
index bbfbebf4affb..df44dd5dc4b2 100644
--- a/sound/firewire/fcp.c
+++ b/sound/firewire/fcp.c
@@ -240,9 +240,7 @@ int fcp_avc_transaction(struct fw_unit *unit,
 	t.response_match_bytes = response_match_bytes;
 	t.state = STATE_PENDING;
 	init_waitqueue_head(&t.wait);
-
-	if (*(const u8 *)command == 0x00 || *(const u8 *)command == 0x03)
-		t.deferrable = true;
+	t.deferrable = (*(const u8 *)command == 0x00 || *(const u8 *)command == 0x03);
 
 	spin_lock_irq(&transactions_lock);
 	list_add_tail(&t.list, &transactions);
-- 
2.31.1