Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2291206pxb; Mon, 11 Jan 2021 06:11:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzT/+Xo6ZGshovwWWqx6792E6wqRnhN5aFfJzF0i4PTBTMEOT3CCKucgSwN0lNN66j0bVkQ X-Received: by 2002:aa7:da8f:: with SMTP id q15mr14066009eds.239.1610374290619; Mon, 11 Jan 2021 06:11:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610374290; cv=none; d=google.com; s=arc-20160816; b=xnzK7pTEU5hOJkcABH1K66r9uz2NHlfdEy5ze/87ttY2gdN4y/LVFEx1FzDoI55CV7 /eoiiy6rLsV+8gclA+Hoj/Og9snyjaN1m7Us7Qdjq1QGu/BOP5ujDugyFKk6f9V8J3hC 4o6eEgzuJcP/OSw1csYLra3qKYZtn0c7hAuL8p7aAKPzLflcAn8My8QYD/inMdTMs8Dm 7xyJD17zVN0AnhpIMTDYGJRcNS5Ss8ZzUv8m39j9oCkZfItTCfDsUi6Kugg4Xj/L33cb w31tqX0Z0oUDAb6AKYITN52coObH4WbTehY9pO3hW8M9QFzLyGHV5xdc6RUVZa9nsGyE I97w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=V/vlskgvdI6rFcXYLdmAeVB0svm+AVzJjrLMv0k7l48=; b=QY1nBkjZR35J1j16TlZk/etrjR2AE9QMzMoldbRfV3M97k2HOEZ3qZ5KVCb/yuFgp5 HIMQ4qacPgE3hfQn1yOsDQOaZfgrIZPCkamqA6uisfCRTZNnWhPzyYJowhlkqm8uje0i hLuW9vJ+NvxHvUM8VUNl7J2sSyQlP8xA6BM4RoW8AANKNawZAdMDKQv7NEqPtBTy3J/1 rrfwUr3+mSxe4wP8n40MHIGRu1zmScqToTDQs4qAUQfPM7/1MMl7biNhB6lLV2u68WeJ kelPDTeh8BO9LulKDucA/hVxyPxqZHRLIHLQ7XvFX2EZmsvOsoJllZrHZ23hfHl+MU1t jDwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dj1si6858955edb.346.2021.01.11.06.11.06; Mon, 11 Jan 2021 06:11:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388776AbhAKOIt (ORCPT + 99 others); Mon, 11 Jan 2021 09:08:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729909AbhAKNDh (ORCPT ); Mon, 11 Jan 2021 08:03:37 -0500 Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 802B4C06179F for ; Mon, 11 Jan 2021 05:02:56 -0800 (PST) Received: from ramsan.of.borg ([84.195.186.194]) by michel.telenet-ops.be with bizsmtp id FR2u2400j4C55Sk06R2uHp; Mon, 11 Jan 2021 14:02:55 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kywqU-002pvS-A9; Mon, 11 Jan 2021 14:02:54 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1kywqT-001W0u-RF; Mon, 11 Jan 2021 14:02:53 +0100 From: Geert Uytterhoeven To: Clemens Ladisch , Takashi Sakamoto , Jaroslav Kysela , Takashi Iwai Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH/RFC 2/2] ALSA: firewire-tascam: Fix integer overflow in midi_port_work() Date: Mon, 11 Jan 2021 14:02:51 +0100 Message-Id: <20210111130251.361335-3-geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210111130251.361335-1-geert+renesas@glider.be> References: <20210111130251.361335-1-geert+renesas@glider.be> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As snd_fw_async_midi_port.consume_bytes is unsigned int, and NSEC_PER_SEC is 1000000000L, the second multiplication in port->consume_bytes * 8 * NSEC_PER_SEC / 31250 always overflows on 32-bit platforms, truncating the result. Fix this by precalculating "NSEC_PER_SEC / 31250", which is an integer constant. Note that this assumes port->consume_bytes <= 16777. Fixes: 531f471834227d03 ("ALSA: firewire-lib/firewire-tascam: localize async midi port") Signed-off-by: Geert Uytterhoeven --- Compile-tested only. I don't know the maximum transfer length of MIDI, but given it's an old standard, I guess it's rather small. If it is larger than 16777, the constant "8" should be replaced by "8ULL", to force 64-bit arithmetic. --- sound/firewire/tascam/tascam-transaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/firewire/tascam/tascam-transaction.c b/sound/firewire/tascam/tascam-transaction.c index 90288b4b46379526..a073cece4a7d5e3a 100644 --- a/sound/firewire/tascam/tascam-transaction.c +++ b/sound/firewire/tascam/tascam-transaction.c @@ -209,7 +209,7 @@ static void midi_port_work(struct work_struct *work) /* Set interval to next transaction. */ port->next_ktime = ktime_add_ns(ktime_get(), - port->consume_bytes * 8 * NSEC_PER_SEC / 31250); + port->consume_bytes * 8 * (NSEC_PER_SEC / 31250)); /* Start this transaction. */ port->idling = false; -- 2.25.1