From patchwork Tue Dec 27 19:44:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Wang X-Patchwork-Id: 133354 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 42875B6F68 for ; Wed, 28 Dec 2011 06:46:43 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753216Ab1L0Tqi (ORCPT ); Tue, 27 Dec 2011 14:46:38 -0500 Received: from mail-qw0-f53.google.com ([209.85.216.53]:64090 "EHLO mail-qw0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753133Ab1L0Tqh (ORCPT ); Tue, 27 Dec 2011 14:46:37 -0500 Received: by qadb15 with SMTP id b15so7904181qad.19 for ; Tue, 27 Dec 2011 11:46:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=kzhUX70UNyiUGuQ3XtwQcBARjgX4wMHwR9Ny2MVuPYU=; b=viNOax83m3ym4xcz7dKJLOScLrmCxRymlkCCOD/TW0SGI0Y8EJIhsh0xnfpr6RB6fI kw0pv5NgHlCjRZkJcDusF1WDkdCw5ZKjp3xfx31g+ZfLTh46a6yAIjJAT6zbl1tqyRSa zw4ieQ23BTd6xiMFmVSiCSd7uIg3HLeXGVJeA= Received: by 10.224.203.67 with SMTP id fh3mr32351492qab.13.1325015196633; Tue, 27 Dec 2011 11:46:36 -0800 (PST) Received: from localhost.localdomain (hchen.csail.mit.edu. [18.26.5.5]) by mx.google.com with ESMTPS id df3sm52959029qab.6.2011.12.27.11.46.34 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 27 Dec 2011 11:46:35 -0800 (PST) From: Xi Wang To: linux-hams@vger.kernel.org Cc: "David S. Miller" , netdev@vger.kernel.org, Ralf Baechle , Xi Wang Subject: [PATCH -next] netrom: avoid overflows in nr_setsockopt() Date: Tue, 27 Dec 2011 14:44:53 -0500 Message-Id: <1325015093-28968-1-git-send-email-xi.wang@gmail.com> X-Mailer: git-send-email 1.7.5.4 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Check setsockopt arguments to avoid overflows and return -EINVAL for too large arguments. Signed-off-by: Xi Wang --- net/netrom/af_netrom.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c index c329b47..7dab229 100644 --- a/net/netrom/af_netrom.c +++ b/net/netrom/af_netrom.c @@ -306,26 +306,26 @@ static int nr_setsockopt(struct socket *sock, int level, int optname, { struct sock *sk = sock->sk; struct nr_sock *nr = nr_sk(sk); - int opt; + unsigned long opt; if (level != SOL_NETROM) return -ENOPROTOOPT; - if (optlen < sizeof(int)) + if (optlen < sizeof(unsigned int)) return -EINVAL; - if (get_user(opt, (int __user *)optval)) + if (get_user(opt, (unsigned int __user *)optval)) return -EFAULT; switch (optname) { case NETROM_T1: - if (opt < 1) + if (opt < 1 || opt > ULONG_MAX / HZ) return -EINVAL; nr->t1 = opt * HZ; return 0; case NETROM_T2: - if (opt < 1) + if (opt < 1 || opt > ULONG_MAX / HZ) return -EINVAL; nr->t2 = opt * HZ; return 0; @@ -337,13 +337,13 @@ static int nr_setsockopt(struct socket *sock, int level, int optname, return 0; case NETROM_T4: - if (opt < 1) + if (opt < 1 || opt > ULONG_MAX / HZ) return -EINVAL; nr->t4 = opt * HZ; return 0; case NETROM_IDLE: - if (opt < 0) + if (opt > ULONG_MAX / (60 * HZ)) return -EINVAL; nr->idle = opt * 60 * HZ; return 0;