Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2290892pxb; Mon, 11 Jan 2021 06:11:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBo9qTM7V380F2Npj+Zivj5HuB+R45TCAO2e+uCh/h4l3PZamLwxBg0avAobDlDL9CAzOf X-Received: by 2002:a17:906:43c5:: with SMTP id j5mr11408599ejn.530.1610374267385; Mon, 11 Jan 2021 06:11:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610374267; cv=none; d=google.com; s=arc-20160816; b=tfnJZTmuOhRuP/473vQstduITq7ZGBqOMepKWKLMYCP+7oHvoPhDY00Rv6qC/oaVOc vMJ6LAQV72oHVDk/p1Ri4lrSDIAvKl35wG9iSLks5BYuIuTIfsBxfCCHztWqwsLeHnk6 OZlXQYMN7fWUdd5pbYyXv578wQN89Ux2d+ApiVIY2lsDUqy7/JDQaHpoECrB+abwZwOX 6sHqNHgbaSCfiBeFl17alWUdqzRiaJp7NY32gHwLWG2mxNvwX9WS8H/th/V9+Qnsp0cw MPrP6uFa0jlATkcqHWHklhQHG7cejxrglwv1k4JemK78+evr8lnPf7K4aoM2bdSV43AH z7/w== 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=wKyJnde2CrjhpZ2kHWCIlZyofqaiyj4G+qQ0S/ZU77g=; b=xROHVQvBc03gqQldVxbHS5wLDGsOm7j3J3klyPtsN2bBkWmOwtxm2qjN84/w2yR+fj /4xAwNk2eRHNP4G7iCaolvNqAUQWFKOsNgAk5/CcgMoHgpfTyjvk89WESSpZvX5K1p/8 RQTlusPmRsCQZFX96eHfxQNELBh7j/ztttskaEHJ6wRDraHx+1Bu2sCrKz2YSZscH58E y6fJtsZQoaa1UEks0+geIWy3bdEJzwNURjBJdp7HI/HBCINNrEIEdUO3Es+6YEjoIqNM 0ySpwZfymjrDhx4zonOFlyDwZXoIueSjel6mtOQB9mHrm0iPiqr7PqAL7xmG2ChxIi5M 7wQw== 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 c25si7327897edx.588.2021.01.11.06.10.42; Mon, 11 Jan 2021 06:11:07 -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 S2388623AbhAKOIq (ORCPT + 99 others); Mon, 11 Jan 2021 09:08:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729913AbhAKNDh (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 7B34EC061794 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 FR2u2400d4C55Sk06R2uHo; 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-002pvR-8d; Mon, 11 Jan 2021 14:02:54 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1kywqT-001W0q-Qb; 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 1/2] ALSA: fireface: Fix integer overflow in transmit_midi_msg() Date: Mon, 11 Jan 2021 14:02:50 +0100 Message-Id: <20210111130251.361335-2-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_ff.rx_bytes[] is unsigned int, and NSEC_PER_SEC is 1000000000L, the second multiplication in ff->rx_bytes[port] * 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 ff->rx_bytes[port] <= 16777. Fixes: 19174295788de77d ("ALSA: fireface: add transaction support") 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/fireface/ff-transaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/firewire/fireface/ff-transaction.c b/sound/firewire/fireface/ff-transaction.c index 7f82762ccc8c80ba..ee7122c461d46f44 100644 --- a/sound/firewire/fireface/ff-transaction.c +++ b/sound/firewire/fireface/ff-transaction.c @@ -88,7 +88,7 @@ static void transmit_midi_msg(struct snd_ff *ff, unsigned int port) /* Set interval to next transaction. */ ff->next_ktime[port] = ktime_add_ns(ktime_get(), - ff->rx_bytes[port] * 8 * NSEC_PER_SEC / 31250); + ff->rx_bytes[port] * 8 * (NSEC_PER_SEC / 31250)); if (quad_count == 1) tcode = TCODE_WRITE_QUADLET_REQUEST; -- 2.25.1