From mboxrd@z Thu Jan 1 00:00:00 1970 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 B1B9954903; Tue, 14 May 2024 11:01:47 +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=1715684507; cv=none; b=nWfePmEuryv0o05kfBECj7OvaKP4PF5qUIt7w36u6/2CrUDwJuh6ilDsRntGJxZUW4zDOK6dtVYQx7LhQ9dx9wKCd2iQwBIpHLe3WlbELbiP5ytDWN5JGfPrjds7jSwk2EiRSkkpWRprFusJCZGOjgD1MegdJifll1kvknh79eY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715684507; c=relaxed/simple; bh=vh0XEF9//zMhd9EEn7G9+m1OD4GEiv2I+6JbPo2QJJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jjtpvHSMTs66FbRqID3uhZkUAhD6vcCEIs6yvo8ucOF6G9oE3vyH+J6u4KzbZmGGkFrZH76jl5lih+02a3HCaPVCJfE8kiVXgCTC5UGQ5ffs0Q94OygvH2tLYO59FZ4ia53vOMZyQKJgi/gqqMA1eNqN4xju79Dq10lsqvoLels= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MOGKzUaL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="MOGKzUaL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18F08C2BD10; Tue, 14 May 2024 11:01:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1715684507; bh=vh0XEF9//zMhd9EEn7G9+m1OD4GEiv2I+6JbPo2QJJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MOGKzUaLQhsK2crg17MzH3irRlE3MgpV9H4HxEzhlZ0X/BlrAAdgTFVh4QiyHtwPS CQplEBPx0F+RrP6jz/9yccdxkY4gQtZ9Oe5wwGLLUexoDFjXmP1x3htZ/cXvVr9yyc OYJeA5prwyDXR+9wQu14GarIyBMvGmGeHehKuLus= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bui Quang Minh , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 049/301] bna: ensure the copied buf is NUL terminated Date: Tue, 14 May 2024 12:15:20 +0200 Message-ID: <20240514101034.096747875@linuxfoundation.org> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514101032.219857983@linuxfoundation.org> References: <20240514101032.219857983@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bui Quang Minh [ Upstream commit 8c34096c7fdf272fd4c0c37fe411cd2e3ed0ee9f ] Currently, we allocate a nbytes-sized kernel buffer and copy nbytes from userspace to that buffer. Later, we use sscanf on this buffer but we don't ensure that the string is terminated inside the buffer, this can lead to OOB read when using sscanf. Fix this issue by using memdup_user_nul instead of memdup_user. Fixes: 7afc5dbde091 ("bna: Add debugfs interface.") Signed-off-by: Bui Quang Minh Link: https://lore.kernel.org/r/20240424-fix-oob-read-v2-2-f1f1b53a10f4@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/brocade/bna/bnad_debugfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/brocade/bna/bnad_debugfs.c b/drivers/net/ethernet/brocade/bna/bnad_debugfs.c index 7246e13dd559f..97291bfbeea58 100644 --- a/drivers/net/ethernet/brocade/bna/bnad_debugfs.c +++ b/drivers/net/ethernet/brocade/bna/bnad_debugfs.c @@ -312,7 +312,7 @@ bnad_debugfs_write_regrd(struct file *file, const char __user *buf, void *kern_buf; /* Copy the user space buf */ - kern_buf = memdup_user(buf, nbytes); + kern_buf = memdup_user_nul(buf, nbytes); if (IS_ERR(kern_buf)) return PTR_ERR(kern_buf); @@ -372,7 +372,7 @@ bnad_debugfs_write_regwr(struct file *file, const char __user *buf, void *kern_buf; /* Copy the user space buf */ - kern_buf = memdup_user(buf, nbytes); + kern_buf = memdup_user_nul(buf, nbytes); if (IS_ERR(kern_buf)) return PTR_ERR(kern_buf); -- 2.43.0