From patchwork Sun Jun 10 19:25:08 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: danborkmann@iogearbox.net X-Patchwork-Id: 164009 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id F3942B6FD7 for ; Mon, 11 Jun 2012 05:25:21 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755450Ab2FJTZR (ORCPT ); Sun, 10 Jun 2012 15:25:17 -0400 Received: from www62.your-server.de ([213.133.104.62]:35682 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751399Ab2FJTZQ (ORCPT ); Sun, 10 Jun 2012 15:25:16 -0400 Received: from [78.46.5.204] (helo=sslproxy02.your-server.de) by www62.your-server.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.74) (envelope-from ) id 1SdnlD-0006JC-OH; Sun, 10 Jun 2012 21:25:15 +0200 Received: from [109.246.197.199] by sslproxy02.your-server.de with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1SdnlC-0003Le-1S; Sun, 10 Jun 2012 21:25:14 +0200 Message-ID: <4FD4F494.6020102@iogearbox.net> Date: Sun, 10 Jun 2012 21:25:08 +0200 From: Daniel Borkmann User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20111110 Icedove/3.0.11 MIME-Version: 1.0 To: "David S. Miller" CC: "netdev@vger.kernel.org" Subject: [PATCH] af_packet: check loop for greater than zero in tpacket_fill_skb X-Authenticated-Sender: danborkmann@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.97.3/15024/Sun Jun 10 00:29:59 2012) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org It could be more safe to check the 'to_write' for 'greater than zero' instead for 'not zero'. 'to_write' is of type int and subtraction operations are performed on it, so in the case of malformed values that are subtracted from 'to_write', it could become less than zero, which is then interpreted as 'not zero' in the while condition, thus the loop won't return as expected. Signed-off-by: Daniel Borkmann --- net/packet/af_packet.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) -- 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 --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 0f66174..3e53680 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -2027,7 +2027,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, skb->truesize += to_write; atomic_add(to_write, &po->sk.sk_wmem_alloc); - while (likely(to_write)) { + while (likely(to_write > 0)) { nr_frags = skb_shinfo(skb)->nr_frags; if (unlikely(nr_frags >= MAX_SKB_FRAGS)) {