Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3718940pxv; Mon, 26 Jul 2021 10:10:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1NDPZhrZr25QH5FWytvpwdiMw77GwBKzYoDS4dyUgSbIUw2NOT/UQDkLT+vcvtuDVQgN4 X-Received: by 2002:adf:f5d1:: with SMTP id k17mr9648637wrp.123.1627319404043; Mon, 26 Jul 2021 10:10:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627319404; cv=none; d=google.com; s=arc-20160816; b=t8XZEsFojvURsJNxghAY+MEWNH/Bwctx/f13zUwjHkfbP7Md9gwsEoO955HpphrfRR +cmL+7y0YvE29I7+Aalz2Tnx5H6vr24VAfH0Z6ijS+Ao5DViEqPunYs5TkrRNSUjUCjQ 6D41gZLGrDQLSRLS7h8+WeILyodIIFM3Zqmmb9415HDzCrXta8NyLH3oVqA8bNfE6c3t 3cfe6VHjw+qAurtGVh3hLkCSbDW5s9oOR4zqQ9O89+E3owLSi/1rHQQ0ikPRKsZbZajL gzOADQld1icRygUsoSPUgyJdhOLru5NNbA/wiWxcP8NJQWwtW45hAIMqyoGU+hDn2SYd GWBw== 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=lntQ38/YddpBtjKeIdAkXf5SLVR64cJjverWhDBADUI=; b=dP4SvGc5+TJXti29tfGTdHabPVS1u0CuDVEn9zqRtcXjE8q9Ea7a4ygiP+ThMo+jEm 9XuoGlw2ULVVo178OKH1nPBl0QIcy2M3/jFqeebwifdHR2H1FpAjE7+vIKbUEofMpgQ2 kJynkFcmepBU/hJ1MkHa//Wq5MwbOplZ4MOiFpGN2qS8JSFE/+ERlqtcH3HCqXBOlW8l +nfMFJ0Cc4mpyPKAioiFyO2Bhdn/5Jb82BoKFcsHiVEMs706Y+4bwCCYxuZNle8rbCBf PrAslOkMKKdux1bCKLJmUyESCb8f91hMT8FHrdBgkiZlDCQfoWiEWFPesGiFyQ+G5AIi qd0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="cOZGWc/N"; 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 p5si212396wmq.146.2021.07.26.10.09.36; Mon, 26 Jul 2021 10:10:04 -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="cOZGWc/N"; 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 S238360AbhGZPlp (ORCPT + 99 others); Mon, 26 Jul 2021 11:41:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:38770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237075AbhGZPXh (ORCPT ); Mon, 26 Jul 2021 11:23:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9162360F5A; Mon, 26 Jul 2021 16:04:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315445; bh=KYOiDckllKXj8mHvVhsWCZDPBlWvtcaE6P/Sx14jxpo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cOZGWc/N2kbxPa1oaVINeP+o+GHRucU8korlMa5Zf6Tf8lEDcfSj1YlhfZqy2PwGG BeaUN6Sf6X3EJWx/rMVeheH3ulwuwN3gfIQudFhGiLLtcGllRb0NKBHZjC3LlN2uu8 EiSy4OgqdMzRdkopg+Cp9tHro9AgFa9YSjwaQMJE= 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 5.10 098/167] sctp: update active_key for asoc when old key is being replaced Date: Mon, 26 Jul 2021 17:38:51 +0200 Message-Id: <20210726153842.688484553@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 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 6f8319b828b0..fe74c5f95630 100644 --- a/net/sctp/auth.c +++ b/net/sctp/auth.c @@ -860,6 +860,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