* [PATCH] tipc: fix error handling of expanding buffer headroom
@ 2015-11-22 7:38 Ying Xue
2015-11-24 4:35 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Ying Xue @ 2015-11-22 7:38 UTC (permalink / raw)
To: davem; +Cc: jon.maloy, stephen, tipc-discussion, scan-admin, netdev
Coverity says:
*** CID 1338065: Error handling issues (CHECKED_RETURN)
/net/tipc/udp_media.c: 162 in tipc_udp_send_msg()
156 struct udp_media_addr *dst = (struct udp_media_addr *)&dest->value;
157 struct udp_media_addr *src = (struct udp_media_addr *)&b->addr.value;
158 struct sk_buff *clone;
159 struct rtable *rt;
160
161 if (skb_headroom(skb) < UDP_MIN_HEADROOM)
>>> CID 1338065: Error handling issues (CHECKED_RETURN)
>>> Calling "pskb_expand_head" without checking return value (as is done elsewhere 51 out of 56 times).
162 pskb_expand_head(skb, UDP_MIN_HEADROOM, 0, GFP_ATOMIC);
163
164 clone = skb_clone(skb, GFP_ATOMIC);
165 skb_set_inner_protocol(clone, htons(ETH_P_TIPC));
166 ub = rcu_dereference_rtnl(b->media_ptr);
167 if (!ub) {
When expanding buffer headroom over udp tunnel with pskb_expand_head(),
it's unfortunate that we don't check its return value. As a result, if
the function returns an error code due to the lack of memory, it may
cause unpredictable consequence as we unconditionally consider that
it's always successful.
Fixes: e53567948f82 ("tipc: conditionally expand buffer headroom over udp tunnel")
Reported-by: <scan-admin@coverity.com>
Cc: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Ying Xue <ying.xue@windriver.com>
---
net/tipc/udp_media.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c
index ad2719a..f01ff16 100644
--- a/net/tipc/udp_media.c
+++ b/net/tipc/udp_media.c
@@ -158,8 +158,11 @@ static int tipc_udp_send_msg(struct net *net, struct sk_buff *skb,
struct udp_media_addr *src = (struct udp_media_addr *)&b->addr.value;
struct rtable *rt;
- if (skb_headroom(skb) < UDP_MIN_HEADROOM)
- pskb_expand_head(skb, UDP_MIN_HEADROOM, 0, GFP_ATOMIC);
+ if (skb_headroom(skb) < UDP_MIN_HEADROOM) {
+ err = pskb_expand_head(skb, UDP_MIN_HEADROOM, 0, GFP_ATOMIC);
+ if (!err)
+ goto tx_error;
+ }
skb_set_inner_protocol(skb, htons(ETH_P_TIPC));
ub = rcu_dereference_rtnl(b->media_ptr);
--
1.7.9.5
------------------------------------------------------------------------------
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] tipc: fix error handling of expanding buffer headroom
2015-11-22 7:38 [PATCH] tipc: fix error handling of expanding buffer headroom Ying Xue
@ 2015-11-24 4:35 ` David Miller
2015-11-24 5:33 ` Ying Xue
0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2015-11-24 4:35 UTC (permalink / raw)
To: ying.xue; +Cc: jon.maloy, stephen, tipc-discussion, scan-admin, netdev
From: Ying Xue <ying.xue@windriver.com>
Date: Sun, 22 Nov 2015 15:38:39 +0800
> @@ -158,8 +158,11 @@ static int tipc_udp_send_msg(struct net *net, struct sk_buff *skb,
> struct udp_media_addr *src = (struct udp_media_addr *)&b->addr.value;
> struct rtable *rt;
>
> - if (skb_headroom(skb) < UDP_MIN_HEADROOM)
> - pskb_expand_head(skb, UDP_MIN_HEADROOM, 0, GFP_ATOMIC);
> + if (skb_headroom(skb) < UDP_MIN_HEADROOM) {
> + err = pskb_expand_head(skb, UDP_MIN_HEADROOM, 0, GFP_ATOMIC);
> + if (!err)
> + goto tx_error;
> + }
pskb_expand_head() returns negative error codes, therefore zero means
success and therefore this "!err" check is reversed.
------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741551&iu=/4140
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] tipc: fix error handling of expanding buffer headroom
2015-11-24 4:35 ` David Miller
@ 2015-11-24 5:33 ` Ying Xue
0 siblings, 0 replies; 3+ messages in thread
From: Ying Xue @ 2015-11-24 5:33 UTC (permalink / raw)
To: David Miller; +Cc: jon.maloy, stephen, tipc-discussion, scan-admin, netdev
On 11/24/2015 12:35 PM, David Miller wrote:
> pskb_expand_head() returns negative error codes, therefore zero means
> success and therefore this "!err" check is reversed.
Thank you for pointing out such a stupid mistake I made.
I will send v2 to correct it.
Regards,
Ying
------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741551&iu=/4140
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-11-24 5:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-22 7:38 [PATCH] tipc: fix error handling of expanding buffer headroom Ying Xue
2015-11-24 4:35 ` David Miller
2015-11-24 5:33 ` Ying Xue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).