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 8B2CF23D7CE for ; Fri, 24 Apr 2026 23:46: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=1777074413; cv=none; b=Szx6dPVYc7mkp286Pitv1wRCJSABkl7Zgf0nUnEy0GAkEc36b8hiOZPMPL+CHc5f1Y7M1tUgPlNKsDUvz6VK19UIw4oPw1lareqMY/ufFISwZtkSGtyHj22toba+8+61wH6d4kr6W9D82ltbg2bmcr3h/EwFqr3P0jPkovk2ks0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777074413; c=relaxed/simple; bh=O940sl2BjhXvDo2j5mrayxjISO7QwDktRzY93NEgxDM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F8rXHiVKsWn9Vsj8e1cFgEJnWYsNU8D7Me0CLNMReCiaJydzl+cYujbXXG5r/ebbdba4JeSnQVh9lJGjP0H4RHShqmHwpVJfGIT1nMSBqMLBLlFpJZBCRN/LKsjvZfP9TvCl7gd6An7rc+T+FthdzRNPTftHpiRXnnsXHIyTbtg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gF4/+P1X; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gF4/+P1X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC6DDC19425; Fri, 24 Apr 2026 23:46:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777074413; bh=O940sl2BjhXvDo2j5mrayxjISO7QwDktRzY93NEgxDM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gF4/+P1XT97KYl4zsDa9geirsWBO3nuqJlSf0vj82ncEK70EAAvRkL+HcnnX9tyOt hoACVx/2t2UgoGAN8LSN8omZXZExP1qkVXLrSfGbsyYTYtEDZUDCFLXFkoIElytpV7 kmHmoOgWPICdeBmbcnX3TVqx417hGeHY4i87TLH8QK0nlotIcZ6K570JxgT+vi6I+x 1fqrIOnhO0MRGwhEJNeM11QoOwjh19o89IwLl2GkM8uvgB9X5163h0YB+EI0g+VeHP JUnNYbZqaNjQvY1kHRTvpXp95GqdnAKKfgLNelRdUFYG7SdXqe4ufQ9+v1NCT99mrw IyGS6pbefw5Ng== From: Sasha Levin To: stable@vger.kernel.org Cc: Tristan Madani , Namjae Jeon , Steve French , Sasha Levin Subject: [PATCH 5.15.y] ksmbd: fix out-of-bounds write in smb2_get_ea() EA alignment Date: Fri, 24 Apr 2026 19:46:50 -0400 Message-ID: <20260424234650.2560965-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026042445-graduate-unvaried-2a31@gregkh> References: <2026042445-graduate-unvaried-2a31@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Tristan Madani [ Upstream commit 30010c952077a1c89ecdd71fc4d574c75a8f5617 ] smb2_get_ea() applies 4-byte alignment padding via memset() after writing each EA entry. The bounds check on buf_free_len is performed before the value memcpy, but the alignment memset fires unconditionally afterward with no check on remaining space. When the EA value exactly fills the remaining buffer (buf_free_len == 0 after value subtraction), the alignment memset writes 1-3 NUL bytes past the buf_free_len boundary. In compound requests where the response buffer is shared across commands, the first command (e.g., READ) can consume most of the buffer, leaving a tight remainder for the QUERY_INFO EA response. The alignment memset then overwrites past the physical kvmalloc allocation into adjacent kernel heap memory. Add a bounds check before the alignment memset to ensure buf_free_len can accommodate the padding bytes. This is the same bug pattern fixed by commit beef2634f81f ("ksmbd: fix potencial OOB in get_file_all_info() for compound requests") and commit fda9522ed6af ("ksmbd: fix OOB write in QUERY_INFO for compound requests"), both of which added bounds checks before unconditional writes in QUERY_INFO response handlers. Cc: stable@vger.kernel.org Fixes: e2b76ab8b5c9 ("ksmbd: add support for read compound") Signed-off-by: Tristan Madani Acked-by: Namjae Jeon Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/ksmbd/smb2pdu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c index 978a103e72bb2..4e2e196c0b0c0 100644 --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -4468,6 +4468,8 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp, /* align next xattr entry at 4 byte bundary */ alignment_bytes = ((next_offset + 3) & ~3) - next_offset; if (alignment_bytes) { + if (buf_free_len < alignment_bytes) + break; memset(ptr, '\0', alignment_bytes); ptr += alignment_bytes; next_offset += alignment_bytes; -- 2.53.0