Skip to content

Commit ec3797f

Browse files
ziming zhangidryomov
authored andcommitted
libceph: replace BUG_ON with bounds check for map->max_osd
OSD indexes come from untrusted network packets. Boundary checks are added to validate these against map->max_osd. [ idryomov: drop BUG_ON in ceph_get_primary_affinity(), minor cosmetic edits ] Cc: stable@vger.kernel.org Signed-off-by: ziming zhang <ezrakiez@gmail.com> Reviewed-by: Ilya Dryomov <idryomov@gmail.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 43962db commit ec3797f

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

net/ceph/osdmap.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,8 +1504,6 @@ static int decode_new_primary_temp(void **p, void *end,
15041504

15051505
u32 ceph_get_primary_affinity(struct ceph_osdmap *map, int osd)
15061506
{
1507-
BUG_ON(osd >= map->max_osd);
1508-
15091507
if (!map->osd_primary_affinity)
15101508
return CEPH_OSD_DEFAULT_PRIMARY_AFFINITY;
15111509

@@ -1514,8 +1512,6 @@ u32 ceph_get_primary_affinity(struct ceph_osdmap *map, int osd)
15141512

15151513
static int set_primary_affinity(struct ceph_osdmap *map, int osd, u32 aff)
15161514
{
1517-
BUG_ON(osd >= map->max_osd);
1518-
15191515
if (!map->osd_primary_affinity) {
15201516
int i;
15211517

@@ -1577,6 +1573,8 @@ static int decode_new_primary_affinity(void **p, void *end,
15771573

15781574
ceph_decode_32_safe(p, end, osd, e_inval);
15791575
ceph_decode_32_safe(p, end, aff, e_inval);
1576+
if (osd >= map->max_osd)
1577+
goto e_inval;
15801578

15811579
ret = set_primary_affinity(map, osd, aff);
15821580
if (ret)
@@ -1879,7 +1877,9 @@ static int decode_new_up_state_weight(void **p, void *end, u8 struct_v,
18791877
ceph_decode_need(p, end, 2*sizeof(u32), e_inval);
18801878
osd = ceph_decode_32(p);
18811879
w = ceph_decode_32(p);
1882-
BUG_ON(osd >= map->max_osd);
1880+
if (osd >= map->max_osd)
1881+
goto e_inval;
1882+
18831883
osdmap_info(map, "osd%d weight 0x%x %s\n", osd, w,
18841884
w == CEPH_OSD_IN ? "(in)" :
18851885
(w == CEPH_OSD_OUT ? "(out)" : ""));
@@ -1905,13 +1905,15 @@ static int decode_new_up_state_weight(void **p, void *end, u8 struct_v,
19051905
u32 xorstate;
19061906

19071907
osd = ceph_decode_32(p);
1908+
if (osd >= map->max_osd)
1909+
goto e_inval;
1910+
19081911
if (struct_v >= 5)
19091912
xorstate = ceph_decode_32(p);
19101913
else
19111914
xorstate = ceph_decode_8(p);
19121915
if (xorstate == 0)
19131916
xorstate = CEPH_OSD_UP;
1914-
BUG_ON(osd >= map->max_osd);
19151917
if ((map->osd_state[osd] & CEPH_OSD_UP) &&
19161918
(xorstate & CEPH_OSD_UP))
19171919
osdmap_info(map, "osd%d down\n", osd);
@@ -1937,7 +1939,9 @@ static int decode_new_up_state_weight(void **p, void *end, u8 struct_v,
19371939
struct ceph_entity_addr addr;
19381940

19391941
osd = ceph_decode_32(p);
1940-
BUG_ON(osd >= map->max_osd);
1942+
if (osd >= map->max_osd)
1943+
goto e_inval;
1944+
19411945
if (struct_v >= 7)
19421946
ret = ceph_decode_entity_addrvec(p, end, msgr2, &addr);
19431947
else

0 commit comments

Comments
 (0)