diff options
author | Ilya Dryomov <idryomov@gmail.com> | 2015-09-14 09:01:05 -0400 |
---|---|---|
committer | Ilya Dryomov <idryomov@gmail.com> | 2015-09-17 13:14:15 -0400 |
commit | 7f61f545657281a3a1b0faf68993165ebdecc51b (patch) | |
tree | d405e22c3eaeb3cb6071ca0fa46b4e8c7c909350 | |
parent | 6ff33f3902c3b1c5d0db6b1e2c70b6d76fba357f (diff) |
libceph: don't access invalid memory in keepalive2 path
This
struct ceph_timespec ceph_ts;
...
con_out_kvec_add(con, sizeof(ceph_ts), &ceph_ts);
wraps ceph_ts into a kvec and adds it to con->out_kvec array, yet
ceph_ts becomes invalid on return from prepare_write_keepalive(). As
a result, we send out bogus keepalive2 stamps. Fix this by encoding
into a ceph_timespec member, similar to how acks are read and written.
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Reviewed-by: Yan, Zheng <zyan@redhat.com>
-rw-r--r-- | include/linux/ceph/messenger.h | 4 | ||||
-rw-r--r-- | net/ceph/messenger.c | 9 |
2 files changed, 8 insertions, 5 deletions
diff --git a/include/linux/ceph/messenger.h b/include/linux/ceph/messenger.h index 7e1252e97a30..b2371d9b51fa 100644 --- a/include/linux/ceph/messenger.h +++ b/include/linux/ceph/messenger.h | |||
@@ -238,6 +238,8 @@ struct ceph_connection { | |||
238 | bool out_kvec_is_msg; /* kvec refers to out_msg */ | 238 | bool out_kvec_is_msg; /* kvec refers to out_msg */ |
239 | int out_more; /* there is more data after the kvecs */ | 239 | int out_more; /* there is more data after the kvecs */ |
240 | __le64 out_temp_ack; /* for writing an ack */ | 240 | __le64 out_temp_ack; /* for writing an ack */ |
241 | struct ceph_timespec out_temp_keepalive2; /* for writing keepalive2 | ||
242 | stamp */ | ||
241 | 243 | ||
242 | /* message in temps */ | 244 | /* message in temps */ |
243 | struct ceph_msg_header in_hdr; | 245 | struct ceph_msg_header in_hdr; |
@@ -248,7 +250,7 @@ struct ceph_connection { | |||
248 | int in_base_pos; /* bytes read */ | 250 | int in_base_pos; /* bytes read */ |
249 | __le64 in_temp_ack; /* for reading an ack */ | 251 | __le64 in_temp_ack; /* for reading an ack */ |
250 | 252 | ||
251 | struct timespec last_keepalive_ack; | 253 | struct timespec last_keepalive_ack; /* keepalive2 ack stamp */ |
252 | 254 | ||
253 | struct delayed_work work; /* send|recv work */ | 255 | struct delayed_work work; /* send|recv work */ |
254 | unsigned long delay; /* current delay interval */ | 256 | unsigned long delay; /* current delay interval */ |
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index 525f454f7531..b9b0e3b5da49 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c | |||
@@ -1353,11 +1353,12 @@ static void prepare_write_keepalive(struct ceph_connection *con) | |||
1353 | dout("prepare_write_keepalive %p\n", con); | 1353 | dout("prepare_write_keepalive %p\n", con); |
1354 | con_out_kvec_reset(con); | 1354 | con_out_kvec_reset(con); |
1355 | if (con->peer_features & CEPH_FEATURE_MSGR_KEEPALIVE2) { | 1355 | if (con->peer_features & CEPH_FEATURE_MSGR_KEEPALIVE2) { |
1356 | struct timespec ts = CURRENT_TIME; | 1356 | struct timespec now = CURRENT_TIME; |
1357 | struct ceph_timespec ceph_ts; | 1357 | |
1358 | ceph_encode_timespec(&ceph_ts, &ts); | ||
1359 | con_out_kvec_add(con, sizeof(tag_keepalive2), &tag_keepalive2); | 1358 | con_out_kvec_add(con, sizeof(tag_keepalive2), &tag_keepalive2); |
1360 | con_out_kvec_add(con, sizeof(ceph_ts), &ceph_ts); | 1359 | ceph_encode_timespec(&con->out_temp_keepalive2, &now); |
1360 | con_out_kvec_add(con, sizeof(con->out_temp_keepalive2), | ||
1361 | &con->out_temp_keepalive2); | ||
1361 | } else { | 1362 | } else { |
1362 | con_out_kvec_add(con, sizeof(tag_keepalive), &tag_keepalive); | 1363 | con_out_kvec_add(con, sizeof(tag_keepalive), &tag_keepalive); |
1363 | } | 1364 | } |