Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp170126lqo; Tue, 7 May 2024 16:29:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVnvKGvvTYvyoM9Ea+an1gz1JEiQ15miIFSsI/W/yz41QIrLa6M1AO6ScfTEkjmbfIkZn9XqPrzkGnKo5crJJQJWVH9p+Oqp+MntRE2rw== X-Google-Smtp-Source: AGHT+IFj5hc2eDC7++M5mW7w+HOkHfTky4YDm48hhhTmVHvBBEfJwnQILGDus6CWm3E/WSNQMcOH X-Received: by 2002:a05:6870:7195:b0:23b:c31f:ee76 with SMTP id 586e51a60fabf-24098c7afeamr1169781fac.52.1715124551867; Tue, 07 May 2024 16:29:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715124551; cv=pass; d=google.com; s=arc-20160816; b=sQVadkjZGiTGQo4I9Ewhkr6M/4gcoaAJxF3NLA+MZ/rL2JbGWrxbX6py7dljyYi0m/ wW1HlSzbYC4gXZY1+dqzTuQFAehZqRvL7N0ePAjb1Gllr0mdydCFr6DhYj5i9a/MW+rK e3PbUElcx7rjXPtS4BkdYw4rwh/xNtKXlgFfE6ZbaH810/JUDcPKVKBCmzZH+4ANf0R0 eS4HoNgS9vhx07yaUjqenORmLksuSasCGdDy2zHquBY8+Ygjv2Sx4NdbYugjogvICKD5 WCdrZu7XxhGZbUlipzrrtjmbpyxRprIifq1lwUjvGL6yMjKmNipLblOiq3uQptyN8Lum 89Dw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tpPnnsKJ88p4VzFST5faahX/2OpmtyyyZYg+QNUEx8Q=; fh=SLbNBLyNQ2xOKqok5FGJ7ie1slhZrLq/kBUUui1tbiQ=; b=N0PJ1zCrTgM+sLAXQCB7H4JYrmvXio+25JRtwwySWYXnhMkwbr32nhqUxn8tlT82KS 0/e/6WnWSRTdmLZy8pWilpbKTh/bKbv8QeFGdK4eVQWfasn3Fx4XRyjPzY+ja1GoNpjv t1zYqNC+aFKfi0HX1t03ePyZrkK1NJHBJQvbM6pGrHl3TeVS68xU961/j6oXo6ZEbY1s tRAiV2YAF4809gZTUkLP/3fV6RfLEUhiRHAeiD7+zuL2y0PI9vPUPOVE2Ehj+Fd6Gac9 CdIY3S1ekyfU0pWmXeRaV4EMGydqlo4PjdK/SN6CtiS0ltIcvD140wRHt154hBThmSHF DTYw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UhnuvFLZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172371-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172371-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l70-20020a639149000000b0061bc3b59f06si10040619pge.669.2024.05.07.16.29.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 16:29:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172371-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UhnuvFLZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172371-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172371-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4FCC32819F6 for ; Tue, 7 May 2024 23:29:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AAC5213FD79; Tue, 7 May 2024 23:08:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UhnuvFLZ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D137F13F45D; Tue, 7 May 2024 23:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715123336; cv=none; b=esDw8oRDvRP1oWjSOwPfdkXGrYZaPQ8Xntf8ILlIrpD1UwE4Ngb9hXT5EuC10zycLXh+TBwKA9IM5f5I4QAcKG6gwC4+N0bwj1Pc7q/1wJsrcnvrlA+aUkX5mcJZrE/xH3nrgL9PJzmMwr/S8Rjz7f8mueIP0pX3gwB6QroexSI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715123336; c=relaxed/simple; bh=f43ozCLdsfglP1LAVYw8NC7+1NYU/w/xvIQAowU7pjQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iFKXmdMpk89PDK6F/1+9kTLQT06u4bN02w7vuvyrTK1XCFOv3Ry6MKl0uP7FENbriZy8gECLBY27pq0CEiClFBhR3dNZxFLwErw5XrmF95y4Kn/oKTtHCxt6LJzyRl/QELNXvcFihafsKSSCoKa34y9P69mQGpgLus5y1t9/xtQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UhnuvFLZ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 003EAC4AF17; Tue, 7 May 2024 23:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715123336; bh=f43ozCLdsfglP1LAVYw8NC7+1NYU/w/xvIQAowU7pjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UhnuvFLZVtvT/oNdGGT6vfP7ldAJyaHBxaihasg4B15wpG++8Hg/Tt7unt8wN+94J n8X2urYC3/Bt2moZO8iF9ezh4+9sigWvRbR05x+xGjL75+gDtRAEWSUVP16Ir2c1v1 dNWfeK8Ci/L7HRlx7iVgZwm/rd+HFDe89qmAhvsj6g+0mPJvp/xFXAIBlmJhSLBob3 DDF93/DkznMQCuvKskTwCKpUHRoKhD4ynZOj8iHh6U9RAPit0a6JsqT0u2oPHwqTk8 FHxJ+379Qoven4IOqXuPiptt4FVzjp3nl47CpuI3mvL4dr1ciPPigeW2mX17+7eGGd xCdN+w6qiKS2A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Thanassis Avgerinos , Takashi Sakamoto , Sasha Levin , linux1394-devel@lists.sourceforge.net Subject: [PATCH AUTOSEL 6.8 29/52] firewire: nosy: ensure user_length is taken into account when fetching packet contents Date: Tue, 7 May 2024 19:06:55 -0400 Message-ID: <20240507230800.392128-29-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240507230800.392128-1-sashal@kernel.org> References: <20240507230800.392128-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.8.9 Content-Transfer-Encoding: 8bit From: Thanassis Avgerinos [ Upstream commit 38762a0763c10c24a4915feee722d7aa6e73eb98 ] Ensure that packet_buffer_get respects the user_length provided. If the length of the head packet exceeds the user_length, packet_buffer_get will now return 0 to signify to the user that no data were read and a larger buffer size is required. Helps prevent user space overflows. Signed-off-by: Thanassis Avgerinos Signed-off-by: Takashi Sakamoto Signed-off-by: Sasha Levin --- drivers/firewire/nosy.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/firewire/nosy.c b/drivers/firewire/nosy.c index b0d671db178a8..ea31ac7ac1ca9 100644 --- a/drivers/firewire/nosy.c +++ b/drivers/firewire/nosy.c @@ -148,10 +148,12 @@ packet_buffer_get(struct client *client, char __user *data, size_t user_length) if (atomic_read(&buffer->size) == 0) return -ENODEV; - /* FIXME: Check length <= user_length. */ + length = buffer->head->length; + + if (length > user_length) + return 0; end = buffer->data + buffer->capacity; - length = buffer->head->length; if (&buffer->head->data[length] < end) { if (copy_to_user(data, buffer->head->data, length)) -- 2.43.0