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 CE65943AD7; Tue, 14 May 2024 11:47:53 +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=1715687273; cv=none; b=ZizaZz7Ixf0hHGVGslWJir2GKiGeUxA/KpDW8zQ06Ex6C7+nXrdTiTYhQb7+3SC7LcpjtmAPLZp1T0Cum8TwHQmKbHyCdEc+xAZFxmrzXtnL6cpxEJrE9Vz1vm8YpSUVy8ahpRnwRkuQ9whEU+VvsxvAct46HwOrdK3yabYV4Oo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715687273; c=relaxed/simple; bh=wx7DjBKHy9bjflbFUjSvLSkCKkF6UswSsBu3hcg1tow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rPbzYF33eL4frGaTbKmHRzlq+bJ96YyRrFpEcl+qA6zYmPnvo4aI+YichUdidhgU02iesKuyomS4j+o0BRJIl5e72fmpGMV23x3lyszyEeNN7zlWuVMR4Lnuxt/7H73FQ4H/i+j4JVeW53k62GTS34PPuDItrb6QOlohaB0wsQw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=mdHetJCQ; 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="mdHetJCQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54585C2BD10; Tue, 14 May 2024 11:47:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1715687273; bh=wx7DjBKHy9bjflbFUjSvLSkCKkF6UswSsBu3hcg1tow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mdHetJCQVZ80F+mcaVAmRcjheWKygaEVhvcDVWjrByLPNfQa7Vb18deTlcZO34G9X X8MNrFgSyICXJDLu28Qu/K4/W2j6B/AMvkWRQ6V3tascdfE4pG8E0Mbf2e3GZTmU2a yalilKYB05RxYfz9SjRu2fXDOEGWQfSFawbIbr2Y= 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.10 022/111] bna: ensure the copied buf is NUL terminated Date: Tue, 14 May 2024 12:19:20 +0200 Message-ID: <20240514100957.969067500@linuxfoundation.org> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514100957.114746054@linuxfoundation.org> References: <20240514100957.114746054@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.10-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