Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3712651pxv; Mon, 26 Jul 2021 10:01:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyw/hqu24rc9yDaqpIQebcvZPCWelk6pxbwlVTZdOcFYKc//aCC2ZerqfIWnHQCGd85fXp3 X-Received: by 2002:a1c:a78a:: with SMTP id q132mr9902672wme.76.1627318917218; Mon, 26 Jul 2021 10:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627318917; cv=none; d=google.com; s=arc-20160816; b=Jl5eOHiL42Tjmri5fct7jOiMqw47PXuCthkKhd79vKWfPGlr9kcYWU8X95RnCitvKf KSsGwZkLAqg6HH8tI/D+6bGbj9CFptebUoygw86eeITwR7BkIwre1QI+NovD01OihriR GwDr3cSlA7E8ezZX2osDTF4CFLmHx8LWF2tz2gjkNG06bWiVFB4x4DQ67NTK2v6w28E4 DdlWt+t3W4u51hY3n36kQw3ZEBlQzEbe/8WdMxeSloCC6cIDOyFR1K4+rp8EKCoKcEOZ RK6jyYMJsO66wKZApgRhV6mM3fR8xnIRTbd2n9yR6Ej/15ckCbYLyXCE6athKfO9PzYm XtRw== 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=m2hoLe/7S1Nhhj9IgvuF2W02ydl5WNZL0Pk25UzwEYU=; b=hxeKPGzcWLwk77RwV0pRywLPqZF7DiuBUDMWzxhJ50Yx0kYPAPEpWNNctzXFy/KJMI UoYyc1QbF3dvsmXlzu8vZqfWxZqZrV6i8NZd8cWk3/kfc0a2sI7nraTOGmhHDtz1iZs/ ZIPwXliBd4WN5Uh6jPDBPo+OUS9VH0JQpGTKaJ9jc+AJOhnSwqZgfOC4xjopgNefi+0e xGexB5WRaRvOcsSVcwx2x6jG3Jyj2+2iOZqrbKxEig1nlOMDImoPfGkgqgLSJjHcKHJ1 S9JotQdFw4FC1GlnqFgyNVWjwdkUu08NiF1O34Sd3JtuzXLTBb17Et522T5rfBA+ODe+ DdnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ad9JleIi; 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 t2si308077wrq.24.2021.07.26.10.01.33; Mon, 26 Jul 2021 10:01:57 -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=Ad9JleIi; 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 S238153AbhGZPjU (ORCPT + 99 others); Mon, 26 Jul 2021 11:39:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:37046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237321AbhGZPWX (ORCPT ); Mon, 26 Jul 2021 11:22:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4809960F9C; Mon, 26 Jul 2021 15:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627314772; bh=xzxagQdLtR+w7t1dWXM9THl7GLFCequ8Q4x6p+iW+mg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ad9JleIiWru2RK3sjoVJyOiOl0kZUvAyx6/u2MZ3gpCFfEvMypUBtDSFdd184M8m+ vQPnqXQN597RlKM3h2W5zz7aUm6kcJrfb1qw4in3Lvwgkkr7OxxGcefZo/RDneyZa4 Gr1+jqjCEnr0Xu22k0c75DOeOywG1iqluhPgFtZ0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+b774577370208727d12b@syzkaller.appspotmail.com, Xin Long , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 086/120] sctp: update active_key for asoc when old key is being replaced Date: Mon, 26 Jul 2021 17:38:58 +0200 Message-Id: <20210726153835.145528741@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153832.339431936@linuxfoundation.org> References: <20210726153832.339431936@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 58acd10092268831e49de279446c314727101292 ] syzbot reported a call trace: BUG: KASAN: use-after-free in sctp_auth_shkey_hold+0x22/0xa0 net/sctp/auth.c:112 Call Trace: sctp_auth_shkey_hold+0x22/0xa0 net/sctp/auth.c:112 sctp_set_owner_w net/sctp/socket.c:131 [inline] sctp_sendmsg_to_asoc+0x152e/0x2180 net/sctp/socket.c:1865 sctp_sendmsg+0x103b/0x1d30 net/sctp/socket.c:2027 inet_sendmsg+0x99/0xe0 net/ipv4/af_inet.c:821 sock_sendmsg_nosec net/socket.c:703 [inline] sock_sendmsg+0xcf/0x120 net/socket.c:723 This is an use-after-free issue caused by not updating asoc->shkey after it was replaced in the key list asoc->endpoint_shared_keys, and the old key was freed. This patch is to fix by also updating active_key for asoc when old key is being replaced with a new one. Note that this issue doesn't exist in sctp_auth_del_key_id(), as it's not allowed to delete the active_key from the asoc. Fixes: 1b1e0bc99474 ("sctp: add refcnt support for sh_key") Reported-by: syzbot+b774577370208727d12b@syzkaller.appspotmail.com Signed-off-by: Xin Long Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sctp/auth.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/sctp/auth.c b/net/sctp/auth.c index 2bd8c80bd85f..b2ca66c4a21d 100644 --- a/net/sctp/auth.c +++ b/net/sctp/auth.c @@ -883,6 +883,8 @@ int sctp_auth_set_key(struct sctp_endpoint *ep, if (replace) { list_del_init(&shkey->key_list); sctp_auth_shkey_release(shkey); + if (asoc && asoc->active_key_id == auth_key->sca_keynumber) + sctp_auth_asoc_init_active_key(asoc, GFP_KERNEL); } list_add(&cur_key->key_list, sh_keys); -- 2.30.2