From patchwork Sun Dec 21 13:42:18 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vegard Nossum X-Patchwork-Id: 15133 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.176.167]) by ozlabs.org (Postfix) with ESMTP id 4C68EDDD01 for ; Mon, 22 Dec 2008 00:40:45 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751976AbYLUNkm (ORCPT ); Sun, 21 Dec 2008 08:40:42 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751898AbYLUNkm (ORCPT ); Sun, 21 Dec 2008 08:40:42 -0500 Received: from ik-out-1112.google.com ([66.249.90.176]:25894 "EHLO ik-out-1112.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751882AbYLUNkl (ORCPT ); Sun, 21 Dec 2008 08:40:41 -0500 Received: by ik-out-1112.google.com with SMTP id c29so356433ika.5 for ; Sun, 21 Dec 2008 05:40:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=FF6ywuR+BarzGq8umwY0EvsyJk1fVe3bEjRUixQcTRk=; b=Evlvz23rqkBQXNGNovbir8vTsz+xqAB8NnSTw1hNtoTk9G1rvLF0L2gTwGnE/4PzHY 98c6tnJyOrPtgvSjUUnYHqK5rAJZr/Q36T1g5DkTH1ftLsVxNXx32vxAQ6icKj5c28Gm 8IdDAQvPo40lWAJlJHbisYRzKf1YakJd/dSqg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=lG/7LCmFYctbm/ZvQvpxYDJ4+l6qdRZ+Rs9102zadHyoAxPc+y8q4ygEKOIPfxxFKg AGsWE1ESLr9oI5ellJVp2LMuONa5l068NgB/z2RVj/xS2GpMDJCYx6o+gsKC3Ea7J57H /cYI0reS/Xds6EYwhebZ9olWoAXTwgW4CShIM= Received: by 10.66.222.6 with SMTP id u6mr5711373ugg.19.1229866837735; Sun, 21 Dec 2008 05:40:37 -0800 (PST) Received: from localhost.localdomain (cm-84.209.125.101.getinternet.no [84.209.125.101]) by mx.google.com with ESMTPS id s8sm6014879uge.18.2008.12.21.05.40.35 (version=SSLv3 cipher=RC4-MD5); Sun, 21 Dec 2008 05:40:36 -0800 (PST) Date: Sun, 21 Dec 2008 14:42:18 +0100 From: Vegard Nossum To: "David S. Miller" Cc: Thomas Graf , Eugene Teo , Andrew Morton , Al Viro , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] netlink: fix (theoretical) overrun in message iteration Message-ID: <20081221134218.GA7959@localhost.localdomain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From bb805d89e84ddb11c9bb58afcfd9a6b37bbe5a9b Mon Sep 17 00:00:00 2001 From: Vegard Nossum Date: Sun, 21 Dec 2008 14:20:49 +0100 Subject: [PATCH] netlink: fix (theoretical) overrun in message iteration See commit 1045b03e07d85f3545118510a587035536030c1c for a detailed explanation of why this patch is necessary. In short, nlmsg_next() can make "remaining" go negative, and the remaining >= sizeof(...) comparison will promote "remaining" to an unsigned type, which means that the expression will evaluate to true for negative numbers, even though it was not intended. I put "theoretical" in the title because I have no evidence that this can actually happen, but I suspect that a crafted netlink packet can trigger some badness. Note that the last test, which seemingly has the exact same problem (also true for nla_ok()), is perfectly OK, since we already know that remaining is positive. Cc: Thomas Graf Signed-off-by: Vegard Nossum --- include/net/netlink.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/include/net/netlink.h b/include/net/netlink.h index 3643bbb..13dd525 100644 --- a/include/net/netlink.h +++ b/include/net/netlink.h @@ -332,7 +332,7 @@ static inline int nlmsg_attrlen(const struct nlmsghdr *nlh, int hdrlen) */ static inline int nlmsg_ok(const struct nlmsghdr *nlh, int remaining) { - return (remaining >= sizeof(struct nlmsghdr) && + return (remaining >= (int) sizeof(struct nlmsghdr) && nlh->nlmsg_len >= sizeof(struct nlmsghdr) && nlh->nlmsg_len <= remaining); }