Skip to content

Commit 6c1ea26

Browse files
committed
libceph: make authorizer destruction independent of ceph_auth_client
Starting the kernel client with cephx disabled and then enabling cephx and restarting userspace daemons can result in a crash: [262671.478162] BUG: unable to handle kernel paging request at ffffebe000000000 [262671.531460] IP: [<ffffffff811cd04a>] kfree+0x5a/0x130 [262671.584334] PGD 0 [262671.635847] Oops: 0000 [#1] SMP [262672.055841] CPU: 22 PID: 2961272 Comm: kworker/22:2 Not tainted 4.2.0-34-generic #39~14.04.1-Ubuntu [262672.162338] Hardware name: Dell Inc. PowerEdge R720/068CDY, BIOS 2.4.3 07/09/2014 [262672.268937] Workqueue: ceph-msgr con_work [libceph] [262672.322290] task: ffff88081c2d0dc0 ti: ffff880149ae8000 task.ti: ffff880149ae8000 [262672.428330] RIP: 0010:[<ffffffff811cd04a>] [<ffffffff811cd04a>] kfree+0x5a/0x130 [262672.535880] RSP: 0018:ffff880149aeba58 EFLAGS: 00010286 [262672.589486] RAX: 000001e000000000 RBX: 0000000000000012 RCX: ffff8807e7461018 [262672.695980] RDX: 000077ff80000000 RSI: ffff88081af2be04 RDI: 0000000000000012 [262672.803668] RBP: ffff880149aeba78 R08: 0000000000000000 R09: 0000000000000000 [262672.912299] R10: ffffebe000000000 R11: ffff880819a60e78 R12: ffff8800aec8df40 [262673.021769] R13: ffffffffc035f70f R14: ffff8807e5b138e0 R15: ffff880da9785840 [262673.131722] FS: 0000000000000000(0000) GS:ffff88081fac0000(0000) knlGS:0000000000000000 [262673.245377] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [262673.303281] CR2: ffffebe000000000 CR3: 0000000001c0d000 CR4: 00000000001406e0 [262673.417556] Stack: [262673.472943] ffff880149aeba88 ffff88081af2be04 ffff8800aec8df40 ffff88081af2be04 [262673.583767] ffff880149aeba98 ffffffffc035f70f ffff880149aebac8 ffff8800aec8df00 [262673.694546] ffff880149aebac8 ffffffffc035c89e ffff8807e5b138e0 ffff8805b047f800 [262673.805230] Call Trace: [262673.859116] [<ffffffffc035f70f>] ceph_x_destroy_authorizer+0x1f/0x50 [libceph] [262673.968705] [<ffffffffc035c89e>] ceph_auth_destroy_authorizer+0x3e/0x60 [libceph] [262674.078852] [<ffffffffc0352805>] put_osd+0x45/0x80 [libceph] [262674.134249] [<ffffffffc035290e>] remove_osd+0xae/0x140 [libceph] [262674.189124] [<ffffffffc0352aa3>] __reset_osd+0x103/0x150 [libceph] [262674.243749] [<ffffffffc0354703>] kick_requests+0x223/0x460 [libceph] [262674.297485] [<ffffffffc03559e2>] ceph_osdc_handle_map+0x282/0x5e0 [libceph] [262674.350813] [<ffffffffc035022e>] dispatch+0x4e/0x720 [libceph] [262674.403312] [<ffffffffc034bd91>] try_read+0x3d1/0x1090 [libceph] [262674.454712] [<ffffffff810ab7c2>] ? dequeue_entity+0x152/0x690 [262674.505096] [<ffffffffc034cb1b>] con_work+0xcb/0x1300 [libceph] [262674.555104] [<ffffffff8108fb3e>] process_one_work+0x14e/0x3d0 [262674.604072] [<ffffffff810901ea>] worker_thread+0x11a/0x470 [262674.652187] [<ffffffff810900d0>] ? rescuer_thread+0x310/0x310 [262674.699022] [<ffffffff810957a2>] kthread+0xd2/0xf0 [262674.744494] [<ffffffff810956d0>] ? kthread_create_on_node+0x1c0/0x1c0 [262674.789543] [<ffffffff817bd81f>] ret_from_fork+0x3f/0x70 [262674.834094] [<ffffffff810956d0>] ? kthread_create_on_node+0x1c0/0x1c0 What happens is the following: (1) new MON session is established (2) old "none" ac is destroyed (3) new "cephx" ac is constructed ... (4) old OSD session (w/ "none" authorizer) is put ceph_auth_destroy_authorizer(ac, osd->o_auth.authorizer) osd->o_auth.authorizer in the "none" case is just a bare pointer into ac, which contains a single static copy for all services. By the time we get to (4), "none" ac, freed in (2), is long gone. On top of that, a new vtable installed in (3) points us at ceph_x_destroy_authorizer(), so we end up trying to destroy a "none" authorizer with a "cephx" destructor operating on invalid memory! To fix this, decouple authorizer destruction from ac and do away with a single static "none" authorizer by making a copy for each OSD or MDS session. Authorizers themselves are independent of ac and so there is no reason for destroy_authorizer() to be an ac op. Make it an op on the authorizer itself by turning ceph_authorizer into a real struct. Fixes: http://tracker.ceph.com/issues/15447 Reported-by: Alan Zhang <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]> Reviewed-by: Sage Weil <[email protected]>
1 parent 02da2d7 commit 6c1ea26

File tree

9 files changed

+62
-65
lines changed

9 files changed

+62
-65
lines changed

fs/ceph/mds_client.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,7 @@ void ceph_put_mds_session(struct ceph_mds_session *s)
386386
atomic_read(&s->s_ref), atomic_read(&s->s_ref)-1);
387387
if (atomic_dec_and_test(&s->s_ref)) {
388388
if (s->s_auth.authorizer)
389-
ceph_auth_destroy_authorizer(
390-
s->s_mdsc->fsc->client->monc.auth,
391-
s->s_auth.authorizer);
389+
ceph_auth_destroy_authorizer(s->s_auth.authorizer);
392390
kfree(s);
393391
}
394392
}
@@ -3900,7 +3898,7 @@ static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
39003898
struct ceph_auth_handshake *auth = &s->s_auth;
39013899

39023900
if (force_new && auth->authorizer) {
3903-
ceph_auth_destroy_authorizer(ac, auth->authorizer);
3901+
ceph_auth_destroy_authorizer(auth->authorizer);
39043902
auth->authorizer = NULL;
39053903
}
39063904
if (!auth->authorizer) {

include/linux/ceph/auth.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
*/
1313

1414
struct ceph_auth_client;
15-
struct ceph_authorizer;
1615
struct ceph_msg;
1716

17+
struct ceph_authorizer {
18+
void (*destroy)(struct ceph_authorizer *);
19+
};
20+
1821
struct ceph_auth_handshake {
1922
struct ceph_authorizer *authorizer;
2023
void *authorizer_buf;
@@ -62,8 +65,6 @@ struct ceph_auth_client_ops {
6265
struct ceph_auth_handshake *auth);
6366
int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
6467
struct ceph_authorizer *a, size_t len);
65-
void (*destroy_authorizer)(struct ceph_auth_client *ac,
66-
struct ceph_authorizer *a);
6768
void (*invalidate_authorizer)(struct ceph_auth_client *ac,
6869
int peer_type);
6970

@@ -112,8 +113,7 @@ extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac);
112113
extern int ceph_auth_create_authorizer(struct ceph_auth_client *ac,
113114
int peer_type,
114115
struct ceph_auth_handshake *auth);
115-
extern void ceph_auth_destroy_authorizer(struct ceph_auth_client *ac,
116-
struct ceph_authorizer *a);
116+
void ceph_auth_destroy_authorizer(struct ceph_authorizer *a);
117117
extern int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
118118
int peer_type,
119119
struct ceph_auth_handshake *a);

include/linux/ceph/osd_client.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ struct ceph_msg;
1616
struct ceph_snap_context;
1717
struct ceph_osd_request;
1818
struct ceph_osd_client;
19-
struct ceph_authorizer;
2019

2120
/*
2221
* completion callback for async writepages

net/ceph/auth.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,9 @@ int ceph_auth_create_authorizer(struct ceph_auth_client *ac,
293293
}
294294
EXPORT_SYMBOL(ceph_auth_create_authorizer);
295295

296-
void ceph_auth_destroy_authorizer(struct ceph_auth_client *ac,
297-
struct ceph_authorizer *a)
296+
void ceph_auth_destroy_authorizer(struct ceph_authorizer *a)
298297
{
299-
mutex_lock(&ac->mutex);
300-
if (ac->ops && ac->ops->destroy_authorizer)
301-
ac->ops->destroy_authorizer(ac, a);
302-
mutex_unlock(&ac->mutex);
298+
a->destroy(a);
303299
}
304300
EXPORT_SYMBOL(ceph_auth_destroy_authorizer);
305301

net/ceph/auth_none.c

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ static void reset(struct ceph_auth_client *ac)
1616
struct ceph_auth_none_info *xi = ac->private;
1717

1818
xi->starting = true;
19-
xi->built_authorizer = false;
2019
}
2120

2221
static void destroy(struct ceph_auth_client *ac)
@@ -39,6 +38,27 @@ static int should_authenticate(struct ceph_auth_client *ac)
3938
return xi->starting;
4039
}
4140

41+
static int ceph_auth_none_build_authorizer(struct ceph_auth_client *ac,
42+
struct ceph_none_authorizer *au)
43+
{
44+
void *p = au->buf;
45+
void *const end = p + sizeof(au->buf);
46+
int ret;
47+
48+
ceph_encode_8_safe(&p, end, 1, e_range);
49+
ret = ceph_entity_name_encode(ac->name, &p, end);
50+
if (ret < 0)
51+
return ret;
52+
53+
ceph_encode_64_safe(&p, end, ac->global_id, e_range);
54+
au->buf_len = p - (void *)au->buf;
55+
dout("%s built authorizer len %d\n", __func__, au->buf_len);
56+
return 0;
57+
58+
e_range:
59+
return -ERANGE;
60+
}
61+
4262
static int build_request(struct ceph_auth_client *ac, void *buf, void *end)
4363
{
4464
return 0;
@@ -57,32 +77,32 @@ static int handle_reply(struct ceph_auth_client *ac, int result,
5777
return result;
5878
}
5979

80+
static void ceph_auth_none_destroy_authorizer(struct ceph_authorizer *a)
81+
{
82+
kfree(a);
83+
}
84+
6085
/*
61-
* build an 'authorizer' with our entity_name and global_id. we can
62-
* reuse a single static copy since it is identical for all services
63-
* we connect to.
86+
* build an 'authorizer' with our entity_name and global_id. it is
87+
* identical for all services we connect to.
6488
*/
6589
static int ceph_auth_none_create_authorizer(
6690
struct ceph_auth_client *ac, int peer_type,
6791
struct ceph_auth_handshake *auth)
6892
{
69-
struct ceph_auth_none_info *ai = ac->private;
70-
struct ceph_none_authorizer *au = &ai->au;
71-
void *p, *end;
93+
struct ceph_none_authorizer *au;
7294
int ret;
7395

74-
if (!ai->built_authorizer) {
75-
p = au->buf;
76-
end = p + sizeof(au->buf);
77-
ceph_encode_8(&p, 1);
78-
ret = ceph_entity_name_encode(ac->name, &p, end - 8);
79-
if (ret < 0)
80-
goto bad;
81-
ceph_decode_need(&p, end, sizeof(u64), bad2);
82-
ceph_encode_64(&p, ac->global_id);
83-
au->buf_len = p - (void *)au->buf;
84-
ai->built_authorizer = true;
85-
dout("built authorizer len %d\n", au->buf_len);
96+
au = kmalloc(sizeof(*au), GFP_NOFS);
97+
if (!au)
98+
return -ENOMEM;
99+
100+
au->base.destroy = ceph_auth_none_destroy_authorizer;
101+
102+
ret = ceph_auth_none_build_authorizer(ac, au);
103+
if (ret) {
104+
kfree(au);
105+
return ret;
86106
}
87107

88108
auth->authorizer = (struct ceph_authorizer *) au;
@@ -92,17 +112,6 @@ static int ceph_auth_none_create_authorizer(
92112
auth->authorizer_reply_buf_len = sizeof (au->reply_buf);
93113

94114
return 0;
95-
96-
bad2:
97-
ret = -ERANGE;
98-
bad:
99-
return ret;
100-
}
101-
102-
static void ceph_auth_none_destroy_authorizer(struct ceph_auth_client *ac,
103-
struct ceph_authorizer *a)
104-
{
105-
/* nothing to do */
106115
}
107116

108117
static const struct ceph_auth_client_ops ceph_auth_none_ops = {
@@ -114,7 +123,6 @@ static const struct ceph_auth_client_ops ceph_auth_none_ops = {
114123
.build_request = build_request,
115124
.handle_reply = handle_reply,
116125
.create_authorizer = ceph_auth_none_create_authorizer,
117-
.destroy_authorizer = ceph_auth_none_destroy_authorizer,
118126
};
119127

120128
int ceph_auth_none_init(struct ceph_auth_client *ac)
@@ -127,7 +135,6 @@ int ceph_auth_none_init(struct ceph_auth_client *ac)
127135
return -ENOMEM;
128136

129137
xi->starting = true;
130-
xi->built_authorizer = false;
131138

132139
ac->protocol = CEPH_AUTH_NONE;
133140
ac->private = xi;

net/ceph/auth_none.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
*/
1313

1414
struct ceph_none_authorizer {
15+
struct ceph_authorizer base;
1516
char buf[128];
1617
int buf_len;
1718
char reply_buf[0];
1819
};
1920

2021
struct ceph_auth_none_info {
2122
bool starting;
22-
bool built_authorizer;
23-
struct ceph_none_authorizer au; /* we only need one; it's static */
2423
};
2524

2625
int ceph_auth_none_init(struct ceph_auth_client *ac);

net/ceph/auth_x.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,14 @@ static int ceph_x_handle_reply(struct ceph_auth_client *ac, int result,
565565
return -EAGAIN;
566566
}
567567

568+
static void ceph_x_destroy_authorizer(struct ceph_authorizer *a)
569+
{
570+
struct ceph_x_authorizer *au = (void *)a;
571+
572+
ceph_x_authorizer_cleanup(au);
573+
kfree(au);
574+
}
575+
568576
static int ceph_x_create_authorizer(
569577
struct ceph_auth_client *ac, int peer_type,
570578
struct ceph_auth_handshake *auth)
@@ -581,6 +589,8 @@ static int ceph_x_create_authorizer(
581589
if (!au)
582590
return -ENOMEM;
583591

592+
au->base.destroy = ceph_x_destroy_authorizer;
593+
584594
ret = ceph_x_build_authorizer(ac, th, au);
585595
if (ret) {
586596
kfree(au);
@@ -643,16 +653,6 @@ static int ceph_x_verify_authorizer_reply(struct ceph_auth_client *ac,
643653
return ret;
644654
}
645655

646-
static void ceph_x_destroy_authorizer(struct ceph_auth_client *ac,
647-
struct ceph_authorizer *a)
648-
{
649-
struct ceph_x_authorizer *au = (void *)a;
650-
651-
ceph_x_authorizer_cleanup(au);
652-
kfree(au);
653-
}
654-
655-
656656
static void ceph_x_reset(struct ceph_auth_client *ac)
657657
{
658658
struct ceph_x_info *xi = ac->private;
@@ -770,7 +770,6 @@ static const struct ceph_auth_client_ops ceph_x_ops = {
770770
.create_authorizer = ceph_x_create_authorizer,
771771
.update_authorizer = ceph_x_update_authorizer,
772772
.verify_authorizer_reply = ceph_x_verify_authorizer_reply,
773-
.destroy_authorizer = ceph_x_destroy_authorizer,
774773
.invalidate_authorizer = ceph_x_invalidate_authorizer,
775774
.reset = ceph_x_reset,
776775
.destroy = ceph_x_destroy,

net/ceph/auth_x.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct ceph_x_ticket_handler {
2626

2727

2828
struct ceph_x_authorizer {
29+
struct ceph_authorizer base;
2930
struct ceph_crypto_key session_key;
3031
struct ceph_buffer *buf;
3132
unsigned int service;

net/ceph/osd_client.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,10 +1087,8 @@ static void put_osd(struct ceph_osd *osd)
10871087
dout("put_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref),
10881088
atomic_read(&osd->o_ref) - 1);
10891089
if (atomic_dec_and_test(&osd->o_ref)) {
1090-
struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth;
1091-
10921090
if (osd->o_auth.authorizer)
1093-
ceph_auth_destroy_authorizer(ac, osd->o_auth.authorizer);
1091+
ceph_auth_destroy_authorizer(osd->o_auth.authorizer);
10941092
kfree(osd);
10951093
}
10961094
}
@@ -2984,7 +2982,7 @@ static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
29842982
struct ceph_auth_handshake *auth = &o->o_auth;
29852983

29862984
if (force_new && auth->authorizer) {
2987-
ceph_auth_destroy_authorizer(ac, auth->authorizer);
2985+
ceph_auth_destroy_authorizer(auth->authorizer);
29882986
auth->authorizer = NULL;
29892987
}
29902988
if (!auth->authorizer) {

0 commit comments

Comments
 (0)