Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4140265rwb; Mon, 21 Nov 2022 04:20:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf4TY1i5xARFxO6asC1PZTsHwZbSGuNfUTBtpgrAw1KHL4we1Sfu/ewZBhup7j92FdhUmXuq X-Received: by 2002:a17:902:c286:b0:176:a880:6d72 with SMTP id i6-20020a170902c28600b00176a8806d72mr255601pld.127.1669033237060; Mon, 21 Nov 2022 04:20:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669033237; cv=none; d=google.com; s=arc-20160816; b=N7cCMZzRw4BZFsgu1MDdfPZkXbuz93E4H+wiXumU/2eOb90FA5ZHSf4LU6A3WeDxSd FILa2aQ1d+wS6ecpVroig1LnYXoc+g1hFiY0U8sNIVt6AqMEJdrrx8TwqdLavbUPlH07 w8yESSiC9RXl7+4J/2GLVGXF2me9oGcqgYrFoHNNqIBOm5pe8Pqa73oizXaiaPCi8uaD cAuGj2lmRsnkrjwJPyN6Wxx59MSBi5t4PuRVv5iWuwMVKRheq+3QknyBG8YfkkLWcC/L rKvOCiwHHQDd438CNnRkXBQQmCLcRUxrei4ZUmnXWiPTXbQcrK1O6uGxlQLjfzE9DOMI 7OGw== 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 :message-id:date:subject:cc:to:from; bh=KjpustOZ6QCtQBc9wqAtzKuwdoun7gIhpHOAoBcwwJ0=; b=YGcelc0Qj8pz2gy7/u9hau3VExetBPNd1UvXur84ACoOqvk6V0CMjqy/6Yqb38FSnW iehNIVAQbikkEE8wpZmtw2PQcIHpa8DxYiUmREK3snHXMcxd7p/jZlIGZY88ueczk/Cb WbdV58pAUZa4qb5CLuCos/vZRsCsPQEJ9PtQkQE/qoQv9Q5HhgzYuW6kfoxoVwlmuNbK OvpozDGVwGqaEF8GdCz30LCmDIDt5Tm94dxN/Sl64N3DqQ+gclEeGOeF1djVaFJI7QoM i1mvhOcVJpEkwMm5VCffKMpCg6fD4Qy+InCCWVuTLkeOMFvS/KDk8cYXWpdayO6Jl65X RzTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u17-20020a170903125100b00180680b8f1bsi10921300plh.264.2022.11.21.04.20.22; Mon, 21 Nov 2022 04:20:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229602AbiKULWN (ORCPT + 92 others); Mon, 21 Nov 2022 06:22:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230251AbiKULVf (ORCPT ); Mon, 21 Nov 2022 06:21:35 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B8EAC1F40 for ; Mon, 21 Nov 2022 03:16:32 -0800 (PST) Received: from canpemm500005.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NG4VY4QvJzqSNF; Mon, 21 Nov 2022 19:12:37 +0800 (CST) Received: from huawei.com (10.175.104.82) by canpemm500005.china.huawei.com (7.192.104.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 21 Nov 2022 19:16:30 +0800 From: Baisong Zhong To: , CC: , , , Subject: [PATCH -next v2] ALSA: seq: fix undefined behavior in bit shift for SNDRV_SEQ_FILTER_USE_EVENT Date: Mon, 21 Nov 2022 19:16:30 +0800 Message-ID: <20221121111630.3119259-1-zhongbaisong@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500005.china.huawei.com (7.192.104.229) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Shifting signed 32-bit value by 31 bits is undefined, so changing significant bit to unsigned. The UBSAN warning calltrace like below: UBSAN: shift-out-of-bounds in sound/core/seq/seq_clientmgr.c:509:22 left shift of 1 by 31 places cannot be represented in type 'int' ... Call Trace: dump_stack_lvl+0x8d/0xcf ubsan_epilogue+0xa/0x44 __ubsan_handle_shift_out_of_bounds+0x1e7/0x208 snd_seq_deliver_single_event.constprop.21+0x191/0x2f0 snd_seq_deliver_event+0x1a2/0x350 snd_seq_kernel_client_dispatch+0x8b/0xb0 snd_seq_client_notify_subscription+0x72/0xa0 snd_seq_ioctl_subscribe_port+0x128/0x160 snd_seq_kernel_client_ctl+0xce/0xf0 snd_seq_oss_create_client+0x109/0x15b alsa_seq_oss_init+0x11c/0x1aa do_one_initcall+0x80/0x440 kernel_init_freeable+0x370/0x3c3 kernel_init+0x1b/0x190 ret_from_fork+0x1f/0x30 Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Baisong Zhong --- v2: update all SNDRV_SEQ_FILTER_* to 1U to keep consistent --- include/uapi/sound/asequencer.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/uapi/sound/asequencer.h b/include/uapi/sound/asequencer.h index 6d4a2c60808d..00d2703e8fca 100644 --- a/include/uapi/sound/asequencer.h +++ b/include/uapi/sound/asequencer.h @@ -328,10 +328,10 @@ typedef int __bitwise snd_seq_client_type_t; #define KERNEL_CLIENT ((__force snd_seq_client_type_t) 2) /* event filter flags */ -#define SNDRV_SEQ_FILTER_BROADCAST (1<<0) /* accept broadcast messages */ -#define SNDRV_SEQ_FILTER_MULTICAST (1<<1) /* accept multicast messages */ -#define SNDRV_SEQ_FILTER_BOUNCE (1<<2) /* accept bounce event in error */ -#define SNDRV_SEQ_FILTER_USE_EVENT (1<<31) /* use event filter */ +#define SNDRV_SEQ_FILTER_BROADCAST (1U<<0) /* accept broadcast messages */ +#define SNDRV_SEQ_FILTER_MULTICAST (1U<<1) /* accept multicast messages */ +#define SNDRV_SEQ_FILTER_BOUNCE (1U<<2) /* accept bounce event in error */ +#define SNDRV_SEQ_FILTER_USE_EVENT (1U<<31) /* use event filter */ struct snd_seq_client_info { int client; /* client number to inquire */ -- 2.25.1