Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2519786pxb; Mon, 19 Apr 2021 07:37:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxa97w1oRuiCtwWR77RU6VJqnvrK9wEsd2ot3Y56PFSL+Y6Oapnyg5UjBCxFxU7QXSrSxjR X-Received: by 2002:a63:c70c:: with SMTP id n12mr12307511pgg.213.1618843054998; Mon, 19 Apr 2021 07:37:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618843054; cv=none; d=google.com; s=arc-20160816; b=RwMxmGP+WZ80DZ+91QvxZKVvtHgb3MShQ3sbNZ/1NcU89wbytGZsW+v7Cn+jnVq7wL 2VMDm25C2GkM+mrtjNlLHlWcCsAgN7uncei3Bishdj1TlFt4eVBHcToS0GCluy7qMKKi HYXNFMd7FKO5lzZTRuZ7smlhokfnTxVaXpJ/bbplxvqOJBni/oU2FH07mOiBnwvXJze/ goMuv3/QHz38WFGX4HUPPUXzWUIdUQM4kwuLZg8A2FsQcdi9cbmBsoV2hEtjzoTluohm pFe4haeub7/yqQ0aA58aIxQNlxR0X0owCHhWGtZbDRKQqDXZQfkM/NEpa7lF8oNrgxo/ Vqhg== 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=nG4T7lfGWIkLaPbCXRZxArf2O/2hW/Gfmrs8mDzN/0M=; b=c7/gIhNCdETszttBX+THm1/xy/qaruays9enmq6KoJaMAp9e+KTpyfh8D/SzB5xv0r 4EkbNzca7Z0wAfObsBTNVgKNManxKRSpE6aX3ljnz5A37MItvPbbMySqFEoPtyuo9Su/ rf6UH9tp0OIN7+0RQZTihoEEkvGwZuIzkUwz1GZDYcqz7zdYnSM08NemR12yapkEKB+y F10dwjmXRqAvOye3DUWCIu7uWlorHROQt8NJHj8QcBVgh9KTItIg1vEan1fWlVCJv9lQ 9kGk8XvnT0h546NVYAah8+Ta7x15p5QHvcdNomIEwIFkR4MB419Qp9X7tgCew9zxNJPm +BjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DxmLK8Jf; 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 k12si17978305pgp.381.2021.04.19.07.37.22; Mon, 19 Apr 2021 07:37:34 -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=DxmLK8Jf; 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 S240270AbhDSNSk (ORCPT + 99 others); Mon, 19 Apr 2021 09:18:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:53186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240358AbhDSNPe (ORCPT ); Mon, 19 Apr 2021 09:15:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 16A5F613CD; Mon, 19 Apr 2021 13:13:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618838003; bh=xaSBZePWGhwc2vZPY3FH6nZxIMDgFMMvdBkWlVYyCN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DxmLK8JfDKB8t1gPxMxc8LnruHRKMSebdJQq/wjLM/LhgkZqNinsBuQOFD2Ud1Apv fm+6yVaFkwGOtpZyY1RpjnuHxWNnObqzuOYXAkAiEkXcB1wUsHKseA39kvqd1GrvsM Iu8x+bNRHffj5kfIx+9LAJtuEjbqQGLZI8uPyq/U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Or Cohen , Xin Long , Marcelo Ricardo Leitner , "David S. Miller" Subject: [PATCH 5.10 001/103] net/sctp: fix race condition in sctp_destroy_sock Date: Mon, 19 Apr 2021 15:05:12 +0200 Message-Id: <20210419130527.841550198@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130527.791982064@linuxfoundation.org> References: <20210419130527.791982064@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore 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: Or Cohen commit b166a20b07382b8bc1dcee2a448715c9c2c81b5b upstream. If sctp_destroy_sock is called without sock_net(sk)->sctp.addr_wq_lock held and sp->do_auto_asconf is true, then an element is removed from the auto_asconf_splist without any proper locking. This can happen in the following functions: 1. In sctp_accept, if sctp_sock_migrate fails. 2. In inet_create or inet6_create, if there is a bpf program attached to BPF_CGROUP_INET_SOCK_CREATE which denies creation of the sctp socket. The bug is fixed by acquiring addr_wq_lock in sctp_destroy_sock instead of sctp_close. This addresses CVE-2021-23133. Reported-by: Or Cohen Reviewed-by: Xin Long Fixes: 610236587600 ("bpf: Add new cgroup attach type to enable sock modifications") Signed-off-by: Or Cohen Acked-by: Marcelo Ricardo Leitner Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sctp/socket.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -1520,11 +1520,9 @@ static void sctp_close(struct sock *sk, /* Supposedly, no process has access to the socket, but * the net layers still may. - * Also, sctp_destroy_sock() needs to be called with addr_wq_lock - * held and that should be grabbed before socket lock. */ - spin_lock_bh(&net->sctp.addr_wq_lock); - bh_lock_sock_nested(sk); + local_bh_disable(); + bh_lock_sock(sk); /* Hold the sock, since sk_common_release() will put sock_put() * and we have just a little more cleanup. @@ -1533,7 +1531,7 @@ static void sctp_close(struct sock *sk, sk_common_release(sk); bh_unlock_sock(sk); - spin_unlock_bh(&net->sctp.addr_wq_lock); + local_bh_enable(); sock_put(sk); @@ -4939,9 +4937,6 @@ static int sctp_init_sock(struct sock *s sk_sockets_allocated_inc(sk); sock_prot_inuse_add(net, sk->sk_prot, 1); - /* Nothing can fail after this block, otherwise - * sctp_destroy_sock() will be called without addr_wq_lock held - */ if (net->sctp.default_auto_asconf) { spin_lock(&sock_net(sk)->sctp.addr_wq_lock); list_add_tail(&sp->auto_asconf_list, @@ -4976,7 +4971,9 @@ static void sctp_destroy_sock(struct soc if (sp->do_auto_asconf) { sp->do_auto_asconf = 0; + spin_lock_bh(&sock_net(sk)->sctp.addr_wq_lock); list_del(&sp->auto_asconf_list); + spin_unlock_bh(&sock_net(sk)->sctp.addr_wq_lock); } sctp_endpoint_free(sp->ep); local_bh_disable();