Skip to content

Commit 589506f

Browse files
Li RongQingidryomov
authored andcommitted
libceph: fix a use after free issue in osdmap_set_max_osd
If the state variable is krealloced successfully, map->osd_state will be freed, once following two reallocation failed, and exit the function without resetting map->osd_state, map->osd_state become a wild pointer. fix it by resetting them after krealloc successfully. Signed-off-by: Li RongQing <roy.qing.li@gmail.com> Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
1 parent dc220db commit 589506f

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

‎net/ceph/osdmap.c‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -671,38 +671,38 @@ static int osdmap_set_max_osd(struct ceph_osdmap *map, int max)
671671
int i;
672672

673673
state = krealloc(map->osd_state, max*sizeof(*state), GFP_NOFS);
674+
if (!state)
675+
return -ENOMEM;
676+
map->osd_state = state;
677+
674678
weight = krealloc(map->osd_weight, max*sizeof(*weight), GFP_NOFS);
675-
addr = krealloc(map->osd_addr, max*sizeof(*addr), GFP_NOFS);
676-
if (!state || !weight || !addr) {
677-
kfree(state);
678-
kfree(weight);
679-
kfree(addr);
679+
if (!weight)
680+
return -ENOMEM;
681+
map->osd_weight = weight;
680682

683+
addr = krealloc(map->osd_addr, max*sizeof(*addr), GFP_NOFS);
684+
if (!addr)
681685
return -ENOMEM;
682-
}
686+
map->osd_addr = addr;
683687

684688
for (i = map->max_osd; i < max; i++) {
685-
state[i] = 0;
686-
weight[i] = CEPH_OSD_OUT;
687-
memset(addr + i, 0, sizeof(*addr));
689+
map->osd_state[i] = 0;
690+
map->osd_weight[i] = CEPH_OSD_OUT;
691+
memset(map->osd_addr + i, 0, sizeof(*map->osd_addr));
688692
}
689693

690-
map->osd_state = state;
691-
map->osd_weight = weight;
692-
map->osd_addr = addr;
693-
694694
if (map->osd_primary_affinity) {
695695
u32 *affinity;
696696

697697
affinity = krealloc(map->osd_primary_affinity,
698698
max*sizeof(*affinity), GFP_NOFS);
699699
if (!affinity)
700700
return -ENOMEM;
701+
map->osd_primary_affinity = affinity;
701702

702703
for (i = map->max_osd; i < max; i++)
703-
affinity[i] = CEPH_OSD_DEFAULT_PRIMARY_AFFINITY;
704-
705-
map->osd_primary_affinity = affinity;
704+
map->osd_primary_affinity[i] =
705+
CEPH_OSD_DEFAULT_PRIMARY_AFFINITY;
706706
}
707707

708708
map->max_osd = max;

0 commit comments

Comments
 (0)