BACKPORT: maple_tree: fix potential out-of-bounds access in mas_wr_end_piv()
commit cd00dd2585c4158e81fdfac0bbcc0446afbad26d upstream. Check the write offset end bounds before using it as the offset into the pivot array. This avoids a possible out-of-bounds access on the pivot array if the write extends to the last slot in the node, in which case the node maximum should be used as the end pivot. akpm: this doesn't affect any current callers, but new users of mapletree may encounter this problem if backported into earlier kernels, so let's fix it in -stable kernels in case of this. Link: https://lkml.kernel.org/r/20230506024752.2550-1-zhangpeng.00@bytedance.com Fixes:54a611b605
("Maple Tree: add new data structure") Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com> Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Change-Id: I992549af25fa9c22f587893d004002d2e004d317 (cherry-picked from commit4e2ad53aba
) Signed-off-by: Suren Baghdasaryan <surenb@google.com>
This commit is contained in:
parent
19dd4101e0
commit
66b5ad3507
@ -4322,11 +4322,13 @@ static inline void mas_wr_end_piv(struct ma_wr_state *wr_mas)
|
||||
{
|
||||
wr_mas->end_piv = wr_mas->r_max;
|
||||
|
||||
while ((wr_mas->mas->last > wr_mas->end_piv) &&
|
||||
(wr_mas->offset_end < wr_mas->node_end))
|
||||
wr_mas->end_piv = wr_mas->pivots[++wr_mas->offset_end];
|
||||
while ((wr_mas->offset_end < wr_mas->node_end) &&
|
||||
(wr_mas->mas->last > wr_mas->pivots[wr_mas->offset_end]))
|
||||
wr_mas->offset_end++;
|
||||
|
||||
if (wr_mas->mas->last > wr_mas->end_piv)
|
||||
if (wr_mas->offset_end < wr_mas->node_end)
|
||||
wr_mas->end_piv = wr_mas->pivots[wr_mas->offset_end];
|
||||
else
|
||||
wr_mas->end_piv = wr_mas->mas->max;
|
||||
|
||||
if (!wr_mas->entry)
|
||||
|
Loading…
Reference in New Issue
Block a user