Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3718910pxv; Mon, 26 Jul 2021 10:10:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTek/XXvd3fdOt/yUb8ZUnkC01LxH0XMtlWaKbFyyehkV+YzVj9XrzxabUh2MMVHrKZWTS X-Received: by 2002:aa7:cd71:: with SMTP id ca17mr2671153edb.58.1627319402758; Mon, 26 Jul 2021 10:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627319402; cv=none; d=google.com; s=arc-20160816; b=mI0aWV0M/CTh+n7H1xHkswseJBfRKc7XSYr0N3KY7NEoOXGboeTS0r8Wg5CK5xyYZo KAQl0UYrXX/RztNd0hJspZ4afaJUY+p8y9uPdkvKRUMRRKzGsp0NL/UrAK48D1h/2AGU WcVeTCo7foGAl51ShY9z8PF16OTLIcNXKsrF0hdhLxSeEtbKb5tb4zAHtcpWJzMwc2mq u+Hx0EUvWScqirjzAI0EuGSBg7iMMA1IMaGSOARU/37GZVOAh6zNDFGwEstcnn2qJzg2 xULzz3nTzUnNAwsKXDjMGxKOziSXo30TeVoS0yoOjCN4WFVnexUlxJ7oiKuqAHLob6b0 LmXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=llb7fNq7Or/he4OUjMnrni/UUNCV7ApBw31+a/aGO54=; b=Bul+hLQZGokscNCRBc0jehuAQfCQKjBcVLJ3T4kZS1jvW4SKUHH///rR8RKgOoeOm9 Y5Pn8KATVLp2AHfoGExpW7efVhOBueqFaaW5uhx1LuUYpPzCgH4e9uMsFPUr+BR3ZyGq u9evKvy/amlgrPYvrA14DHFTprD3E7wbez8Vlng1IgNV+Pi0/WQ4vd1Sst8GvDgBZS04 4Jzx073bOwjRsQSGaj0hOQ55/fy3LYEBOg5pd3Vv3HfJ3S/bcpFQCT5AAKpCgsXrpUDy WBZbPMXA4FZvAaBlUy+DL9V1fSpP97hiBHtL9XnUeAeWtFAQyjnY8Z0TDjqsrlfPfMaE JG+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AWUdhyn6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d24si464374ede.181.2021.07.26.10.09.36; Mon, 26 Jul 2021 10:10:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AWUdhyn6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238461AbhGZPnG (ORCPT + 99 others); Mon, 26 Jul 2021 11:43:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:38916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237699AbhGZPX7 (ORCPT ); Mon, 26 Jul 2021 11:23:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B40BC60F38; Mon, 26 Jul 2021 16:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315468; bh=YivcaPsQI6HankPicUPjChr6cFmEqlsylh88FIfEJFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AWUdhyn6I701Yqex0tVCkgFm/Ifl39sm7+QLJeqmR42zGnWp/rmf2wkFoQSOpkfN3 5z8ChJmHIA3fYZQOCBuWYiuq169t2vi7HXp/Kmvlfaugx3hE+5WuNyKme0lH96lov1 g8zqMRaUQuXhwbyfLhmTISiI9mVobSw2TqvTQA6U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Long , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 073/167] sctp: trim optlen when its a huge value in sctp_setsockopt Date: Mon, 26 Jul 2021 17:38:26 +0200 Message-Id: <20210726153841.842563570@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153839.371771838@linuxfoundation.org> References: <20210726153839.371771838@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Long [ Upstream commit 2f3fdd8d4805015fa964807e1c7f3d88f31bd389 ] After commit ca84bd058dae ("sctp: copy the optval from user space in sctp_setsockopt"), it does memory allocation in sctp_setsockopt with the optlen, and it would fail the allocation and return error if the optlen from user space is a huge value. This breaks some sockopts, like SCTP_HMAC_IDENT, SCTP_RESET_STREAMS and SCTP_AUTH_KEY, as when processing these sockopts before, optlen would be trimmed to a biggest value it needs when optlen is a huge value, instead of failing the allocation and returning error. This patch is to fix the allocation failure when it's a huge optlen from user space by trimming it to the biggest size sctp sockopt may need when necessary, and this biggest size is from sctp_setsockopt_reset_streams() for SCTP_RESET_STREAMS, which is bigger than those for SCTP_HMAC_IDENT and SCTP_AUTH_KEY. Fixes: ca84bd058dae ("sctp: copy the optval from user space in sctp_setsockopt") Signed-off-by: Xin Long Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sctp/socket.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 3ac6b21ecf2c..e872bc50bbe6 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -4471,6 +4471,10 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname, } if (optlen > 0) { + /* Trim it to the biggest size sctp sockopt may need if necessary */ + optlen = min_t(unsigned int, optlen, + PAGE_ALIGN(USHRT_MAX + + sizeof(__u16) * sizeof(struct sctp_reset_streams))); kopt = memdup_sockptr(optval, optlen); if (IS_ERR(kopt)) return PTR_ERR(kopt); -- 2.30.2