Skip to content

Commit e1afacb

Browse files
committed
Merge tag 'ceph-for-6.18-rc8' of https://github.com/ceph/ceph-client
Pull ceph fixes from Ilya Dryomov: "A patch to make sparse read handling work in msgr2 secure mode from Slava and a couple of fixes from Ziming and myself to avoid operating on potentially invalid memory, all marked for stable" * tag 'ceph-for-6.18-rc8' of https://github.com/ceph/ceph-client: libceph: prevent potential out-of-bounds writes in handle_auth_session_key() libceph: replace BUG_ON with bounds check for map->max_osd ceph: fix crash in process_v2_sparse_read() for encrypted directories libceph: drop started parameter of __ceph_open_session() libceph: fix potential use-after-free in have_mon_and_osd_map()
2 parents 1f5e808 + 7fce830 commit e1afacb

7 files changed

Lines changed: 66 additions & 42 deletions

File tree

fs/ceph/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc,
11491149
const char *path = fsc->mount_options->server_path ?
11501150
fsc->mount_options->server_path + 1 : "";
11511151

1152-
err = __ceph_open_session(fsc->client, started);
1152+
err = __ceph_open_session(fsc->client);
11531153
if (err < 0)
11541154
goto out;
11551155

include/linux/ceph/libceph.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ struct ceph_entity_addr *ceph_client_addr(struct ceph_client *client);
306306
u64 ceph_client_gid(struct ceph_client *client);
307307
extern void ceph_destroy_client(struct ceph_client *client);
308308
extern void ceph_reset_client_addr(struct ceph_client *client);
309-
extern int __ceph_open_session(struct ceph_client *client,
310-
unsigned long started);
309+
extern int __ceph_open_session(struct ceph_client *client);
311310
extern int ceph_open_session(struct ceph_client *client);
312311
int ceph_wait_for_latest_osdmap(struct ceph_client *client,
313312
unsigned long timeout);

net/ceph/auth_x.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ static int handle_auth_session_key(struct ceph_auth_client *ac, u64 global_id,
631631

632632
/* connection secret */
633633
ceph_decode_32_safe(p, end, len, e_inval);
634+
ceph_decode_need(p, end, len, e_inval);
634635
dout("%s connection secret blob len %d\n", __func__, len);
635636
if (len > 0) {
636637
dp = *p + ceph_x_encrypt_offset();
@@ -648,6 +649,7 @@ static int handle_auth_session_key(struct ceph_auth_client *ac, u64 global_id,
648649

649650
/* service tickets */
650651
ceph_decode_32_safe(p, end, len, e_inval);
652+
ceph_decode_need(p, end, len, e_inval);
651653
dout("%s service tickets blob len %d\n", __func__, len);
652654
if (len > 0) {
653655
ret = ceph_x_proc_ticket_reply(ac, &th->session_key,

net/ceph/ceph_common.c

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -785,42 +785,53 @@ void ceph_reset_client_addr(struct ceph_client *client)
785785
}
786786
EXPORT_SYMBOL(ceph_reset_client_addr);
787787

788-
/*
789-
* true if we have the mon map (and have thus joined the cluster)
790-
*/
791-
static bool have_mon_and_osd_map(struct ceph_client *client)
792-
{
793-
return client->monc.monmap && client->monc.monmap->epoch &&
794-
client->osdc.osdmap && client->osdc.osdmap->epoch;
795-
}
796-
797788
/*
798789
* mount: join the ceph cluster, and open root directory.
799790
*/
800-
int __ceph_open_session(struct ceph_client *client, unsigned long started)
791+
int __ceph_open_session(struct ceph_client *client)
801792
{
802-
unsigned long timeout = client->options->mount_timeout;
803-
long err;
793+
DEFINE_WAIT_FUNC(wait, woken_wake_function);
794+
long timeout = ceph_timeout_jiffies(client->options->mount_timeout);
795+
bool have_monmap, have_osdmap;
796+
int err;
804797

805798
/* open session, and wait for mon and osd maps */
806799
err = ceph_monc_open_session(&client->monc);
807800
if (err < 0)
808801
return err;
809802

810-
while (!have_mon_and_osd_map(client)) {
811-
if (timeout && time_after_eq(jiffies, started + timeout))
812-
return -ETIMEDOUT;
803+
add_wait_queue(&client->auth_wq, &wait);
804+
for (;;) {
805+
mutex_lock(&client->monc.mutex);
806+
err = client->auth_err;
807+
have_monmap = client->monc.monmap && client->monc.monmap->epoch;
808+
mutex_unlock(&client->monc.mutex);
809+
810+
down_read(&client->osdc.lock);
811+
have_osdmap = client->osdc.osdmap && client->osdc.osdmap->epoch;
812+
up_read(&client->osdc.lock);
813+
814+
if (err || (have_monmap && have_osdmap))
815+
break;
816+
817+
if (signal_pending(current)) {
818+
err = -ERESTARTSYS;
819+
break;
820+
}
821+
822+
if (!timeout) {
823+
err = -ETIMEDOUT;
824+
break;
825+
}
813826

814827
/* wait */
815828
dout("mount waiting for mon_map\n");
816-
err = wait_event_interruptible_timeout(client->auth_wq,
817-
have_mon_and_osd_map(client) || (client->auth_err < 0),
818-
ceph_timeout_jiffies(timeout));
819-
if (err < 0)
820-
return err;
821-
if (client->auth_err < 0)
822-
return client->auth_err;
829+
timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, timeout);
823830
}
831+
remove_wait_queue(&client->auth_wq, &wait);
832+
833+
if (err)
834+
return err;
824835

825836
pr_info("client%llu fsid %pU\n", ceph_client_gid(client),
826837
&client->fsid);
@@ -833,12 +844,11 @@ EXPORT_SYMBOL(__ceph_open_session);
833844
int ceph_open_session(struct ceph_client *client)
834845
{
835846
int ret;
836-
unsigned long started = jiffies; /* note the start time */
837847

838848
dout("open_session start\n");
839849
mutex_lock(&client->mount_mutex);
840850

841-
ret = __ceph_open_session(client, started);
851+
ret = __ceph_open_session(client);
842852

843853
mutex_unlock(&client->mount_mutex);
844854
return ret;

net/ceph/debugfs.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ static int monmap_show(struct seq_file *s, void *p)
3636
int i;
3737
struct ceph_client *client = s->private;
3838

39+
mutex_lock(&client->monc.mutex);
3940
if (client->monc.monmap == NULL)
40-
return 0;
41+
goto out_unlock;
4142

4243
seq_printf(s, "epoch %d\n", client->monc.monmap->epoch);
4344
for (i = 0; i < client->monc.monmap->num_mon; i++) {
@@ -48,6 +49,9 @@ static int monmap_show(struct seq_file *s, void *p)
4849
ENTITY_NAME(inst->name),
4950
ceph_pr_addr(&inst->addr));
5051
}
52+
53+
out_unlock:
54+
mutex_unlock(&client->monc.mutex);
5155
return 0;
5256
}
5357

@@ -56,13 +60,14 @@ static int osdmap_show(struct seq_file *s, void *p)
5660
int i;
5761
struct ceph_client *client = s->private;
5862
struct ceph_osd_client *osdc = &client->osdc;
59-
struct ceph_osdmap *map = osdc->osdmap;
63+
struct ceph_osdmap *map;
6064
struct rb_node *n;
6165

66+
down_read(&osdc->lock);
67+
map = osdc->osdmap;
6268
if (map == NULL)
63-
return 0;
69+
goto out_unlock;
6470

65-
down_read(&osdc->lock);
6671
seq_printf(s, "epoch %u barrier %u flags 0x%x\n", map->epoch,
6772
osdc->epoch_barrier, map->flags);
6873

@@ -131,6 +136,7 @@ static int osdmap_show(struct seq_file *s, void *p)
131136
seq_printf(s, "]\n");
132137
}
133138

139+
out_unlock:
134140
up_read(&osdc->lock);
135141
return 0;
136142
}

net/ceph/messenger_v2.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,13 +1061,16 @@ static int decrypt_control_remainder(struct ceph_connection *con)
10611061
static int process_v2_sparse_read(struct ceph_connection *con,
10621062
struct page **pages, int spos)
10631063
{
1064-
struct ceph_msg_data_cursor *cursor = &con->v2.in_cursor;
1064+
struct ceph_msg_data_cursor cursor;
10651065
int ret;
10661066

1067+
ceph_msg_data_cursor_init(&cursor, con->in_msg,
1068+
con->in_msg->sparse_read_total);
1069+
10671070
for (;;) {
10681071
char *buf = NULL;
10691072

1070-
ret = con->ops->sparse_read(con, cursor, &buf);
1073+
ret = con->ops->sparse_read(con, &cursor, &buf);
10711074
if (ret <= 0)
10721075
return ret;
10731076

@@ -1085,11 +1088,11 @@ static int process_v2_sparse_read(struct ceph_connection *con,
10851088
} else {
10861089
struct bio_vec bv;
10871090

1088-
get_bvec_at(cursor, &bv);
1091+
get_bvec_at(&cursor, &bv);
10891092
len = min_t(int, len, bv.bv_len);
10901093
memcpy_page(bv.bv_page, bv.bv_offset,
10911094
spage, soff, len);
1092-
ceph_msg_data_advance(cursor, len);
1095+
ceph_msg_data_advance(&cursor, len);
10931096
}
10941097
spos += len;
10951098
ret -= len;

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)