Received: by 10.192.165.148 with SMTP id m20csp1281995imm; Wed, 2 May 2018 18:16:36 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpKbIpQ9xNYgTOon/Y8zTyYQy3c5IohY15VZJphgv5uirzK3Rftrq1gJWSX0vGMhXGMwYeb X-Received: by 2002:a17:902:7782:: with SMTP id o2-v6mr22684979pll.247.1525310196472; Wed, 02 May 2018 18:16:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525310196; cv=none; d=google.com; s=arc-20160816; b=XHo+KtDPo9OqkkDLgiOU7HDVsPW2Hsat/2AXxAkCdbVEO4Xko/0B9DOaAFD4+HC5Xy Vm1YcT9mrdVeo8PLf+chNzgTSjSSyYkkgpU0J7nm1x0baM2mDxomucKYa1IsYX8+8QmP 9K/swCl3xkronkfgCGpSbyRWHozTTuFPx2TF+EuOmLmp6zjoh6yl3+MA1o6A792tKodZ Bkdsh8OooTheTIJrc4sjaYgqNBG40c+sKD2Ug+4o7Qn7OvVMm3q9mBNjNPEtKL/zGm86 /GOeHFNrknP6aYsjCoDSJAiq8/WRWStYpzvD7Fsdb6OqBDHlYz7/efI3mT1RYwv+8Z16 N5iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=kAB8GJh7NWDMwb69+vz5KlJIpQqQi0ZzLi1sQ+144nE=; b=kt1t3AdulrwFbk/Hnoq8pIzTE5ItdcjaPly8VUUhd0GHtD+2KhKrDHDo9dKtPYNrP6 YwHjqaaRXATFbl5sTM/677iUnuwZswpNxpi+OZ92v4FY9BvPGjFeSeexvkxFvfvvu3sD Lwfx/ae2kJy/2FjIAzxjPOGrzwvRTzbsfwti0YfdJaM00ctgm0LQsusazYGT8TqZa3Wn VxtuOk2jXFlG4w2kZPzMzBvUmNJt7gDkIw/wBfuqhDGv3IDK481S/y5b3K0g/WjcgI94 CSnOoPJb5lM7wQ8iYIdck64e1I6p8+5+PKdhRf51AFjyMBZHddJojTStSAFzKd2OEK0V +03Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=XWY4RRaC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b78si12580410pfj.2.2018.05.02.18.16.22; Wed, 02 May 2018 18:16:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=XWY4RRaC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751950AbeECBP6 (ORCPT + 99 others); Wed, 2 May 2018 21:15:58 -0400 Received: from mta-p6.oit.umn.edu ([134.84.196.206]:44718 "EHLO mta-p6.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751895AbeECBPx (ORCPT ); Wed, 2 May 2018 21:15:53 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id 2A5CB73B for ; Thu, 3 May 2018 01:15:53 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p6.oit.umn.edu ([127.0.0.1]) by localhost (mta-p6.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xF49NXm0K54C for ; Wed, 2 May 2018 20:15:53 -0500 (CDT) Received: from mail-io0-f199.google.com (mail-io0-f199.google.com [209.85.223.199]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p6.oit.umn.edu (Postfix) with ESMTPS id F3A8BB7 for ; Wed, 2 May 2018 20:15:52 -0500 (CDT) Received: by mail-io0-f199.google.com with SMTP id n21-v6so11040773iob.17 for ; Wed, 02 May 2018 18:15:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id; bh=kAB8GJh7NWDMwb69+vz5KlJIpQqQi0ZzLi1sQ+144nE=; b=XWY4RRaCv/DMYPgKV38QvwWaRC3jnpjBZCn4vh6Edsm4+fGKbd8newSbTanwZoIaAA O19JzbKFC5PYfuT9aKfO5ids5hczJGn+3ubNF001ZrIe4fTgGCB3uE+o1MtOsxnT8CRA l+tMewH0+sRRxviViZzclWcAXYXBe63PecoqSKdfPyPVb9jmJMrtQ77s2PrP17GeKw8y S6H0V6Q6BuXAk2+IPTR5WC6iwR5vBY+gZYIgKByKxOmJMHLPSuF0bEKIFys/3FVI5uZe 6mE+hd3ln9cTO8R25J8As3pF9xPjWapRnIVcEtAl5WEUsXE6LXwTRmHray3rs/teb5/X se3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=kAB8GJh7NWDMwb69+vz5KlJIpQqQi0ZzLi1sQ+144nE=; b=i6arNk7eWGW12gqvtkcA7SVWGMjw0IZ0FcGfmAk5H0C9pJTVkCb+/Kd+zoGyhEFkI0 QHOOOFJrct4TRyr2FhgzUMlbsqDKjsK22SxyXQOlLid5DNDzh+p8eWmWa/KU6TPxMQHI 7lHZSldixDgJuPNM/LiOh8XRMf5F0K8pW3qQC9+5Ay1Ae7UxgF8yK7BGVRNbS8DEs8Vo pzkIQPL9zVHH0vi/3N+EidvfxJiUuRhKe9DVpE8G0/Wh2XxLdQViFCllDce8yiiKrugZ yXaR0QVlUsA71l/o1SyS/NwBxQ9GzfSMFqUCZAQ4obBTb2Dxh3dZ9fMUyYDxzzgXx0j9 N33g== X-Gm-Message-State: ALQs6tDRBceDU7FV3TF3itnDxFF4uQ5dCRGlp9c4RF1X1vXCRbs4GIDY Brvorx5eSoCUtzZQaoH5QNn5u6ugV3bQBS8vTTL3OIfwX5/wjxKT4XwG0/qwKzQ6PhtaP4w9Kmg c+csRu9DYAAhD/OkgK1QTNmYYwLA/ X-Received: by 2002:a6b:afe4:: with SMTP id p97-v6mr21473998ioo.257.1525310152641; Wed, 02 May 2018 18:15:52 -0700 (PDT) X-Received: by 2002:a6b:afe4:: with SMTP id p97-v6mr21473994ioo.257.1525310152441; Wed, 02 May 2018 18:15:52 -0700 (PDT) Received: from cs-u-cslp16.cs.umn.edu (cs-u-cslp16.cs.umn.edu. [134.84.121.95]) by smtp.gmail.com with ESMTPSA id d1-v6sm6446325iti.33.2018.05.02.18.15.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 May 2018 18:15:51 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Kangjie Lu , Vlad Yasevich , Neil Horman , "David S. Miller" , linux-sctp@vger.kernel.org (open list:SCTP PROTOCOL), netdev@vger.kernel.org (open list:NETWORKING [GENERAL]), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] sctp: fix a potential missing-check bug Date: Wed, 2 May 2018 20:15:45 -0500 Message-Id: <1525310145-28102-1-git-send-email-wang6495@umn.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In sctp_setsockopt_maxseg(), the integer 'val' is compared against min_len and max_len to check whether it is in the appropriate range. If it is not, an error code -EINVAL will be returned. This is enforced by a security check. But, this check is only executed when 'val' is not 0. In fact, if 'val' is 0, it will be assigned with a new value (if the return value of the function sctp_id2assoc() is not 0) in the following execution. However, this new value of 'val' is not checked before it is used to assigned to asoc->user_frag. That means it is possible that the new value of 'val' could be out of the expected range. This can cause security issues such as buffer overflows, e.g., the new value of 'val' is used as an index to access a buffer. This patch inserts a check for the new value of 'val' to see if it is in the expected range. If it is not, an error code -EINVAL will be returned. Signed-off-by: Wenwen Wang --- net/sctp/socket.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 80835ac..03e1cc3 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -3212,6 +3212,7 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned struct sctp_af *af = sp->pf->af; struct sctp_assoc_value params; struct sctp_association *asoc; + int min_len, max_len; int val; if (optlen == sizeof(int)) { @@ -3231,19 +3232,15 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned return -EINVAL; } - if (val) { - int min_len, max_len; + min_len = SCTP_DEFAULT_MINSEGMENT - af->net_header_len; + min_len -= af->ip_options_len(sk); + min_len -= sizeof(struct sctphdr) + + sizeof(struct sctp_data_chunk); - min_len = SCTP_DEFAULT_MINSEGMENT - af->net_header_len; - min_len -= af->ip_options_len(sk); - min_len -= sizeof(struct sctphdr) + - sizeof(struct sctp_data_chunk); + max_len = SCTP_MAX_CHUNK_LEN - sizeof(struct sctp_data_chunk); - max_len = SCTP_MAX_CHUNK_LEN - sizeof(struct sctp_data_chunk); - - if (val < min_len || val > max_len) - return -EINVAL; - } + if (val && (val < min_len || val > max_len)) + return -EINVAL; asoc = sctp_id2assoc(sk, params.assoc_id); if (asoc) { @@ -3253,6 +3250,9 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned val -= sizeof(struct sctphdr) + sctp_datachk_len(&asoc->stream); } + /* Check the new val to make sure it is in the range. */ + if (val < min_len || val > max_len) + return -EINVAL; asoc->user_frag = val; asoc->frag_point = sctp_frag_point(asoc, asoc->pathmtu); } else { -- 2.7.4