Skip to contentSkip to conversation

tipc: move premature initialization of stack variables

PATCH In review Jon Maloy 2 participants 3 messages Apr 27, 2017 – Apr 28, 2017 Stable branch

lore
Share & tools
lore

Jon Maloy

author
#0 lore raw

PATCH 1/1 tipc: move premature initialization of stack variables

From: Jon Paul Maloy <[email protected]>

commit 681a55d71799b575f46fe94121728cf67460d1c3 upstream

(Slightly modified to apply cleanly)

In the function tipc_rcv() we initialize a couple of stack variables from the message header before that same header has been validated. In rare cases when the arriving header is non-linear, the validation function itself may linearize the buffer by calling skb_may_pull(), while the wrongly initialized stack fields are not updated accordingly.

We fix this in this commit.

Conflicts:
net/tipc/node.c

---
 net/tipc/node.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
net/tipc/node.c +7 -5
index 2df0b98..6660690 100644
@@ -1272,18 +1272,20 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b)
 {
 	struct sk_buff_head xmitq;
 	struct tipc_node *n;
-	struct tipc_msg *hdr = buf_msg(skb);
-	int usr = msg_user(hdr);
+	struct tipc_msg *hdr;
 	int bearer_id = b->identity;
 	struct tipc_link_entry *le;
-	u16 bc_ack = msg_bcast_ack(hdr);
-	int rc = 0;
+	int usr, rc = 0;
+	u16 bc_ack;
 
 	__skb_queue_head_init(&xmitq);
 
-	/* Ensure message is well-formed */
+	/* Ensure message is well-formed before touching the header */
 	if (unlikely(!tipc_msg_validate(skb)))
 		goto discard;
+	hdr = buf_msg(skb);
+	usr = msg_user(hdr);
+	bc_ack = msg_bcast_ack(hdr);
 
 	/* Handle arrival of discovery or broadcast packet */
 	if (unlikely(msg_non_seq(hdr))) {
Signature · 1 line
2.1.4
#1 lore raw
Quoted 5 lines · Jon Maloy

From: Jon Paul Maloy <[email protected]>

commit 681a55d71799b575f46fe94121728cf67460d1c3 upstream

(Slightly modified to apply cleanly)

Belongs below the --- line.

Quoted 7 lines

In the function tipc_rcv() we initialize a couple of stack variables from the message header before that same header has been validated. In rare cases when the arriving header is non-linear, the validation function itself may linearize the buffer by calling skb_may_pull(), while the wrongly initialized stack fields are not updated accordingly.

Quoted 8 lines

We fix this in this commit.

Conflicts:
net/tipc/node.c

What are these lines for? Please don't do that, "Conflicts:" lines do not belong in the changelog as they don't make any sense, right?

thanks,

greg k-h

#2 lore raw
Quoted 22 lines · Greg KH
Quoted 5 lines · Jon Maloy

From: Jon Paul Maloy <[email protected]>

commit 681a55d71799b575f46fe94121728cf67460d1c3 upstream

(Slightly modified to apply cleanly)

Belongs below the --- line.

Quoted 13 lines

In the function tipc_rcv() we initialize a couple of stack variables from the message header before that same header has been validated. In rare cases when the arriving header is non-linear, the validation function itself may linearize the buffer by calling skb_may_pull(), while the wrongly initialized stack fields are not updated accordingly.

We fix this in this commit.

Quoted 5 lines
Quoted 2 lines

Conflicts:
net/tipc/node.c

What are these lines for? Please don't do that, "Conflicts:" lines do not belong in the changelog as they don't make any sense, right?

Oh, and please fix this up and resend, I didn't take this patch.

greg k-h