Skip to content

Commit eef7d73

Browse files
Al Viroteigland
authored andcommitted
dlm: dlm_process_incoming_buffer() fixes
* check that length is large enough to cover the non-variable part of message or rcom resp. (after checking that it's large enough to cover the header, of course). * kill more pointless casts Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: David Teigland <teigland@redhat.com>
1 parent 8b0d8e0 commit eef7d73

4 files changed

Lines changed: 36 additions & 24 deletions

File tree

‎fs/dlm/dlm_internal.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ struct dlm_rcom {
403403
char rc_buf[0];
404404
};
405405

406+
union dlm_packet {
407+
struct dlm_header header; /* common to other two */
408+
struct dlm_message message;
409+
struct dlm_rcom rcom;
410+
};
411+
406412
struct rcom_config {
407413
uint32_t rf_lvblen;
408414
uint32_t rf_lsflags;

‎fs/dlm/lock.c‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,21 +3822,20 @@ void dlm_receive_message_saved(struct dlm_ls *ls, struct dlm_message *ms)
38223822
standard locking activity) or an RCOM (recovery message sent as part of
38233823
lockspace recovery). */
38243824

3825-
void dlm_receive_buffer(struct dlm_header *hd, int nodeid)
3825+
void dlm_receive_buffer(union dlm_packet *p, int nodeid)
38263826
{
3827-
struct dlm_message *ms = (struct dlm_message *) hd;
3828-
struct dlm_rcom *rc = (struct dlm_rcom *) hd;
3827+
struct dlm_header *hd = &p->header;
38293828
struct dlm_ls *ls;
38303829
int type = 0;
38313830

38323831
switch (hd->h_cmd) {
38333832
case DLM_MSG:
3834-
dlm_message_in(ms);
3835-
type = ms->m_type;
3833+
dlm_message_in(&p->message);
3834+
type = p->message.m_type;
38363835
break;
38373836
case DLM_RCOM:
3838-
dlm_rcom_in(rc);
3839-
type = rc->rc_type;
3837+
dlm_rcom_in(&p->rcom);
3838+
type = p->rcom.rc_type;
38403839
break;
38413840
default:
38423841
log_print("invalid h_cmd %d from %u", hd->h_cmd, nodeid);
@@ -3856,7 +3855,7 @@ void dlm_receive_buffer(struct dlm_header *hd, int nodeid)
38563855
hd->h_lockspace, nodeid, hd->h_cmd, type);
38573856

38583857
if (hd->h_cmd == DLM_RCOM && type == DLM_RCOM_STATUS)
3859-
dlm_send_ls_not_ready(nodeid, rc);
3858+
dlm_send_ls_not_ready(nodeid, &p->rcom);
38603859
return;
38613860
}
38623861

@@ -3865,9 +3864,9 @@ void dlm_receive_buffer(struct dlm_header *hd, int nodeid)
38653864

38663865
down_read(&ls->ls_recv_active);
38673866
if (hd->h_cmd == DLM_MSG)
3868-
dlm_receive_message(ls, ms, nodeid);
3867+
dlm_receive_message(ls, &p->message, nodeid);
38693868
else
3870-
dlm_receive_rcom(ls, rc, nodeid);
3869+
dlm_receive_rcom(ls, &p->rcom, nodeid);
38713870
up_read(&ls->ls_recv_active);
38723871

38733872
dlm_put_lockspace(ls);

‎fs/dlm/lock.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void dlm_print_rsb(struct dlm_rsb *r);
1717
void dlm_dump_rsb(struct dlm_rsb *r);
1818
void dlm_print_lkb(struct dlm_lkb *lkb);
1919
void dlm_receive_message_saved(struct dlm_ls *ls, struct dlm_message *ms);
20-
void dlm_receive_buffer(struct dlm_header *hd, int nodeid);
20+
void dlm_receive_buffer(union dlm_packet *p, int nodeid);
2121
int dlm_modes_compat(int mode1, int mode2);
2222
void dlm_put_rsb(struct dlm_rsb *r);
2323
void dlm_hold_rsb(struct dlm_rsb *r);

‎fs/dlm/midcomms.c‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ int dlm_process_incoming_buffer(int nodeid, const void *base,
6161
union {
6262
unsigned char __buf[DLM_INBUF_LEN];
6363
/* this is to force proper alignment on some arches */
64-
struct dlm_header dlm;
64+
union dlm_packet p;
6565
} __tmp;
66-
struct dlm_header *msg = &__tmp.dlm;
66+
union dlm_packet *p = &__tmp.p;
6767
int ret = 0;
6868
int err = 0;
6969
uint16_t msglen;
@@ -75,15 +75,22 @@ int dlm_process_incoming_buffer(int nodeid, const void *base,
7575
message may wrap around the end of the buffer back to the
7676
start, so we need to use a temp buffer and copy_from_cb. */
7777

78-
copy_from_cb(msg, base, offset, sizeof(struct dlm_header),
78+
copy_from_cb(p, base, offset, sizeof(struct dlm_header),
7979
limit);
8080

81-
msglen = le16_to_cpu(msg->h_length);
82-
lockspace = msg->h_lockspace;
81+
msglen = le16_to_cpu(p->header.h_length);
82+
lockspace = p->header.h_lockspace;
8383

8484
err = -EINVAL;
8585
if (msglen < sizeof(struct dlm_header))
8686
break;
87+
if (p->header.h_cmd == DLM_MSG) {
88+
if (msglen < sizeof(struct dlm_message))
89+
break;
90+
} else {
91+
if (msglen < sizeof(struct dlm_rcom))
92+
break;
93+
}
8794
err = -E2BIG;
8895
if (msglen > dlm_config.ci_buffer_size) {
8996
log_print("message size %d from %d too big, buf len %d",
@@ -104,26 +111,26 @@ int dlm_process_incoming_buffer(int nodeid, const void *base,
104111
in the buffer on the stack (which should work for most
105112
ordinary messages). */
106113

107-
if (msglen > DLM_INBUF_LEN && msg == &__tmp.dlm) {
108-
msg = kmalloc(dlm_config.ci_buffer_size, GFP_KERNEL);
109-
if (msg == NULL)
114+
if (msglen > sizeof(__tmp) && p == &__tmp.p) {
115+
p = kmalloc(dlm_config.ci_buffer_size, GFP_KERNEL);
116+
if (p == NULL)
110117
return ret;
111118
}
112119

113-
copy_from_cb(msg, base, offset, msglen, limit);
120+
copy_from_cb(p, base, offset, msglen, limit);
114121

115-
BUG_ON(lockspace != msg->h_lockspace);
122+
BUG_ON(lockspace != p->header.h_lockspace);
116123

117124
ret += msglen;
118125
offset += msglen;
119126
offset &= (limit - 1);
120127
len -= msglen;
121128

122-
dlm_receive_buffer(msg, nodeid);
129+
dlm_receive_buffer(p, nodeid);
123130
}
124131

125-
if (msg != &__tmp.dlm)
126-
kfree(msg);
132+
if (p != &__tmp.p)
133+
kfree(p);
127134

128135
return err ? err : ret;
129136
}

0 commit comments

Comments
 (0)