diff mbox

[2/2] tipc: potential divide by zero in tipc_link_recv_fragment()

Message ID 20130506182912.GB21347@elgon.mountain
State Awaiting Upstream, archived
Delegated to: David Miller
Headers show

Commit Message

Dan Carpenter May 6, 2013, 6:29 p.m. UTC
The worry here is that fragm_sz could be zero since it comes from
skb->data.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Sergei Shtylyov May 6, 2013, 6:38 p.m. UTC | #1
Hello.

On 06-05-2013 22:29, Dan Carpenter wrote:

> The worry here is that fragm_sz could be zero since it comes from
> skb->data.

> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

> diff --git a/net/tipc/link.c b/net/tipc/link.c
> index 3a6064b3..de94493 100644
> --- a/net/tipc/link.c
> +++ b/net/tipc/link.c
> @@ -2524,14 +2524,16 @@ int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
>   		struct tipc_msg *imsg = (struct tipc_msg *)msg_data(fragm);
>   		u32 msg_sz = msg_size(imsg);
>   		u32 fragm_sz = msg_data_sz(fragm);
> -		u32 exp_fragm_cnt = msg_sz/fragm_sz + !!(msg_sz % fragm_sz);
> +		u32 exp_fragm_cnt;
>   		u32 max =  TIPC_MAX_USER_MSG_SIZE + NAMED_H_SIZE;
> +
>   		if (msg_type(imsg) == TIPC_MCAST_MSG)
>   			max = TIPC_MAX_USER_MSG_SIZE + MCAST_H_SIZE;
> -		if (msg_size(imsg) > max) {
> +		if (fragm_sz == 0 || msg_size(imsg) > max) {
>   			kfree_skb(fbuf);
>   			return 0;
>   		}
> +		exp_fragm_cnt = msg_sz/fragm_sz + !!(msg_sz % fragm_sz);

    Don't you think spaces around / should be added at least for 
consistency with %?

WBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dan Carpenter May 6, 2013, 6:49 p.m. UTC | #2
On Mon, May 06, 2013 at 10:38:53PM +0400, Sergei Shtylyov wrote:
> Hello.
> 
> On 06-05-2013 22:29, Dan Carpenter wrote:
> 
> >The worry here is that fragm_sz could be zero since it comes from
> >skb->data.
> 
> >Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> >diff --git a/net/tipc/link.c b/net/tipc/link.c
> >index 3a6064b3..de94493 100644
> >--- a/net/tipc/link.c
> >+++ b/net/tipc/link.c
> >@@ -2524,14 +2524,16 @@ int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
> >  		struct tipc_msg *imsg = (struct tipc_msg *)msg_data(fragm);
> >  		u32 msg_sz = msg_size(imsg);
> >  		u32 fragm_sz = msg_data_sz(fragm);
> >-		u32 exp_fragm_cnt = msg_sz/fragm_sz + !!(msg_sz % fragm_sz);
> >+		u32 exp_fragm_cnt;
> >  		u32 max =  TIPC_MAX_USER_MSG_SIZE + NAMED_H_SIZE;
> >+
> >  		if (msg_type(imsg) == TIPC_MCAST_MSG)
> >  			max = TIPC_MAX_USER_MSG_SIZE + MCAST_H_SIZE;
> >-		if (msg_size(imsg) > max) {
> >+		if (fragm_sz == 0 || msg_size(imsg) > max) {
> >  			kfree_skb(fbuf);
> >  			return 0;
> >  		}
> >+		exp_fragm_cnt = msg_sz/fragm_sz + !!(msg_sz % fragm_sz);
> 
>    Don't you think spaces around / should be added at least for
> consistency with %?

Yep.  I missed that.  I'll resend.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/tipc/link.c b/net/tipc/link.c
index 3a6064b3..de94493 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -2524,14 +2524,16 @@  int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
 		struct tipc_msg *imsg = (struct tipc_msg *)msg_data(fragm);
 		u32 msg_sz = msg_size(imsg);
 		u32 fragm_sz = msg_data_sz(fragm);
-		u32 exp_fragm_cnt = msg_sz/fragm_sz + !!(msg_sz % fragm_sz);
+		u32 exp_fragm_cnt;
 		u32 max =  TIPC_MAX_USER_MSG_SIZE + NAMED_H_SIZE;
+
 		if (msg_type(imsg) == TIPC_MCAST_MSG)
 			max = TIPC_MAX_USER_MSG_SIZE + MCAST_H_SIZE;
-		if (msg_size(imsg) > max) {
+		if (fragm_sz == 0 || msg_size(imsg) > max) {
 			kfree_skb(fbuf);
 			return 0;
 		}
+		exp_fragm_cnt = msg_sz/fragm_sz + !!(msg_sz % fragm_sz);
 		pbuf = tipc_buf_acquire(msg_size(imsg));
 		if (pbuf != NULL) {
 			pbuf->next = *pending;