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 8F1E0136648; Tue, 14 May 2024 11:42:55 +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=1715686975; cv=none; b=AZ0HTBaqYH2s0826Qb722WLbTIX0e3oGVIE9K/1pin/H9CnJD2IkSKfHvaiQE31Kmf97+yDlApE0CW3EsVahdAjtI2plevJI8F2494siYe8ivam3IsSpL66chtXbgnYkdP5ze5CKNvVWZZsFXpK2dOgGWEig/oTacjTvrtRSHNE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715686975; c=relaxed/simple; bh=fuF0yqRFBsJPrgyiL0B2y2X1iezBjTVZ6ha6lyYIUNs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sI4xDTiCPveKGuPAD+XA2aS4i6PIDjDO3rijDm3XTgHhYoGZnYOr2PPmUEC1nLHyeoXKCjxcvtve22WN5iukfU48wZgvzu29h00ktxIBMPvOPOAOqhtILqT/5VFZeD+AQsBZPGCLCIOvpHtwIexZOmUTJW0nW8/fx+B2nVnuxwc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=X77A5QW1; 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="X77A5QW1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17DF2C2BD10; Tue, 14 May 2024 11:42:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1715686975; bh=fuF0yqRFBsJPrgyiL0B2y2X1iezBjTVZ6ha6lyYIUNs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X77A5QW1RRoUQ9BVLqgRMlnCR+goZR+gbrmTpiadE+6oQNNUjgQclxRCoG5fpGGpA I5I3F06ukGJMScwE++gSWnk4lFI26ofFQzfkOG/AAqjyOQv3DpFHY2Pwuu7d8CrMcs YL9BAfGmJmjFvyAPcw6FgPBnAOuZ/JEGoFwM/OS8= 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 5.4 22/84] bna: ensure the copied buf is NUL terminated Date: Tue, 14 May 2024 12:19:33 +0200 Message-ID: <20240514100952.529388048@linuxfoundation.org> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514100951.686412426@linuxfoundation.org> References: <20240514100951.686412426@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 5.4-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 04ad0f2b9677e..777f0d7e48192 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