libceph: don't access invalid memory in keepalive2 path
Ilya Dryomov
maintainerPATCH 1/1 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.
--- include/linux/ceph/messenger.h | 4 +++- net/ceph/messenger.c | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-)
include/linux/ceph/messenger.h +3 -1
@@ -238,6 +238,8 @@ struct ceph_connection {bool out_kvec_is_msg;/* kvec refers to out_msg */ int out_more;/* there is more data after the kvecs */ __le64 out_temp_ack;/* for writing an ack */ +struct ceph_timespec out_temp_keepalive2;/* for writing keepalive2 +stamp */ /* message in temps */ struct ceph_msg_header in_hdr;
@@ -248,7 +250,7 @@ struct ceph_connection {int in_base_pos;/* bytes read */ __le64 in_temp_ack;/* for reading an ack */ -struct timespec last_keepalive_ack; +struct timespec last_keepalive_ack;/* keepalive2 ack stamp */ struct delayed_work work;/* send|recv work */ unsigned long delay;/* current delay interval */
net/ceph/messenger.c +5 -4
@@ -1353,11 +1353,12 @@ static void prepare_write_keepalive(struct ceph_connection *con)dout ("prepare_write_keepalive %p\n" , con);con_out_kvec_reset (con);if (con->peer_features &CEPH_FEATURE_MSGR_KEEPALIVE2 ) { -struct timespec ts =CURRENT_TIME ; -struct ceph_timespec ceph_ts; -ceph_encode_timespec (&ceph_ts, &ts); +struct timespec now =CURRENT_TIME ; +con_out_kvec_add (con,sizeof (tag_keepalive2), &tag_keepalive2); -con_out_kvec_add (con,sizeof (ceph_ts), &ceph_ts); +ceph_encode_timespec (&con->out_temp_keepalive2, &now); +con_out_kvec_add (con,sizeof (con->out_temp_keepalive2), + &con->out_temp_keepalive2); }else {con_out_kvec_add (con,sizeof (tag_keepalive), &tag_keepalive); }
Signature · 1 line
1.9.3
Quoted 51 lines · Ilya Dryomov
This
struct ceph_timespec ceph_ts; ... con_out_kvec_add(con, sizeof(ceph_ts), &ceph_ts);wraps
ceph_tsinto a kvec and adds it tocon->out_kvecarray, yetceph_tsbecomes invalid on return fromprepare_write_keepalive(). As a result, we send out bogus keepalive2 stamps. Fix this by encoding into aceph_timespecmember, similar to how acks are read and written.Signed-off-by Ilya Dryomov <[email protected]>--- include/linux/ceph/messenger.h | 4 +++- net/ceph/messenger.c | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-)include/linux/ceph/messenger.h +3
-1@@ -238,6 +238,8 @@ struct ceph_connection {bool out_kvec_is_msg;/* kvec refers to out_msg */ int out_more;/* there is more data after the kvecs */ __le64 out_temp_ack;/* for writing an ack */ +struct ceph_timespec out_temp_keepalive2;/* for writing keepalive2 +stamp */ /* message in temps */ struct ceph_msg_header in_hdr;@@ -248,7 +250,7 @@ struct ceph_connection {int in_base_pos;/* bytes read */ __le64 in_temp_ack;/* for reading an ack */ -struct timespec last_keepalive_ack; +struct timespec last_keepalive_ack;/* keepalive2 ack stamp */ struct delayed_work work;/* send|recv work */ unsigned long delay;/* current delay interval */ net/ceph/messenger.c +1
-3@@ -1353,11 +1353,12 @@ static void prepare_write_keepalive(struct ceph_connection *con)dout ("prepare_write_keepalive %p\n" , con);con_out_kvec_reset (con);if (con->peer_features &CEPH_FEATURE_MSGR_KEEPALIVE2 ) { -struct timespec ts =CURRENT_TIME ; -struct ceph_timespec ceph_ts; -ceph_encode_timespec (&ceph_ts, &ts); +struct timespec now =CURRENT_TIME ;
net/ceph/messenger.c static void prepare_write_keepalive(struct ceph_connection *con)
Quoted 10 lines
net/ceph/messenger.c +4
-2+con_out_kvec_add (con,sizeof (tag_keepalive2), &tag_keepalive2); -con_out_kvec_add (con,sizeof (ceph_ts), &ceph_ts); +ceph_encode_timespec (&con->out_temp_keepalive2, &now); +con_out_kvec_add (con,sizeof (con->out_temp_keepalive2), + &con->out_temp_keepalive2); }else {con_out_kvec_add (con,sizeof (tag_keepalive), &tag_keepalive); } --
Sorry for introducing this bug
Quoted 6 lines
1.9.3
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html