Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp174240lqo; Tue, 7 May 2024 16:40:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUE2M0y9sfMn2OJlp3VHCqIIBEVpaI07PaNPn0KnwXHeUFyGA4x4Tf/XF+D1VsTOZnQdGBHbjvMqnvh+do3myoLZujr/euxk06f3eOFXg== X-Google-Smtp-Source: AGHT+IHLsKBh9ISZK2h3E1rC6DThucj74AgyZs6DRLSClp+JejnypeXqJV0t7j4jbBkesWHCGZ+q X-Received: by 2002:a9d:76da:0:b0:6f0:64c5:2e52 with SMTP id 46e09a7af769-6f0b7e9daf6mr1022005a34.27.1715125232846; Tue, 07 May 2024 16:40:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715125232; cv=pass; d=google.com; s=arc-20160816; b=xJu/6v5/8Tx0kLsry970EQBau6i7cWw6/KEK4qbpBGX1TUWOqU8GedruUAERNdDJMs gJUrY4mv5/Y5J4+VERkr4ETZezALTQWlWWGvdCMFD5jMaf5zcW/ZpMSI7z4oQlF43Qkm CX7C/OLdlh1a7C5RKR26mba2NHmFWGAaoBcSUIDR2HcoDqufJ9rbMBdQ6uR7rpK3On2S cWQBp8ihMYpBnuDZ1mDrXpvdzaqVSsgsuBnMx6RyVCZ7q2KC9NEtECZWvQvs7CgRyrsC YeshBAbfv4GqkRkobZXpSQsobDutDTdifUiQraexusVBg17kaRLtfyJveh9VFjBiaNmV F4Gw== 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=oBnW5EdW+rGPGFWjj59mTBZI39Rm0ONhE6iycXzwNMVFBoiPlSIa0diT+8zOee/fcm 8e3a1K/XAzNLGd6pocI/Xg7R6Hz2A1l1LMdXtnVtjA8skuvKVWGSn7dPoSekThOaRIXX LBl83talkAKWD1J2J1l9xMvDD0lEPR/Uy4h1iYJer+U9NKdkoBkDrIh09KH3llzY/s/N d3XKeZ4OV/FYPYzGOLGO0Tlx5fI6CoHgZdiseF6e9+5nkPgz+T02RCBlRwRrVI5tSn6B pmw7HMRITUSiPP7M880ZFvqvalGHtS/2ClFuy5AfY9qAxWWsdbRrNnJ6nIfqOb4mcz1f Vabw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FelSheqh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172419-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172419-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id wg13-20020a05620a568d00b007929163caabsi7316025qkn.39.2024.05.07.16.40.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 16:40:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172419-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FelSheqh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-172419-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172419-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8CB381C2362F for ; Tue, 7 May 2024 23:40:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E109516D4C1; Tue, 7 May 2024 23:11:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FelSheqh" 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 11AB515F3E1; Tue, 7 May 2024 23:11:19 +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=1715123480; cv=none; b=onUJtWOUByi69BJGH/rulN9fL/Vxk5meFKN3mpdvlt5NrtkPR/fcrWEqwhMIGfwyVvrC1hTdsi3jGAL+eOUDt4OCJWQJ8hDrgsrxiWt6KaQPGlCX9fPEq4BvfABGeMydh1rndQ4AT0eYM823ErKeJ5Pg4YGJ4fHNrVUpi9KsGFs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715123480; c=relaxed/simple; bh=f43ozCLdsfglP1LAVYw8NC7+1NYU/w/xvIQAowU7pjQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O0ZpDbsuumdSeEgjCde8BR9n6UAkdf2np91OExUZPI1KvRye0HE1IWYHmtpJr0nMhIDdDyaIPfDmJu0Zdr7vA8w7M7vU2V0QGy/vuubIiR7sHe22kwdy3m3/7meTvPtptRrQm3ZgxSq1aci8fw3/tMkO9Wvj0IxvtiKeJiNudzU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FelSheqh; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB4DFC4AF67; Tue, 7 May 2024 23:11:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715123479; bh=f43ozCLdsfglP1LAVYw8NC7+1NYU/w/xvIQAowU7pjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FelSheqhBAC4ZvNSr0pcF5c7swSjrQYqKReAEqsytkQeCb1WP/OCF/zJXKX2GiFps 36O8sB8DpAiyG151UwLcV9pezCKUU1QoYDdIsLl36Uv5sTifG0h3zrqyCrWxN/FZRR zZ5wsUxtCHb4+h4oidjNz+bp3q7BjYnpuNNNIRqntPD8R6XDYPDNxDjrodfoi6z7SR JrA+X9bTGWwr2Nfm4x4XkKksvnWdC8owC67EXy3FKtcqYEHXWspHF2TVOBKD+OBUCi CLAL4tORCQ74KuRGSuv+TUYU6X3dL3SNM0brwI3zHGdML70v02NOf7tTtxmS9Vp7Zj PnOZ7APyGHlNA== 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.6 24/43] firewire: nosy: ensure user_length is taken into account when fetching packet contents Date: Tue, 7 May 2024 19:09:45 -0400 Message-ID: <20240507231033.393285-24-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240507231033.393285-1-sashal@kernel.org> References: <20240507231033.393285-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.6.30 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