Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3695134pxv; Mon, 26 Jul 2021 09:34:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykskR9LzDfDR0BBJ/kMuj1UwqlAG4yqY4gPdKdZVNn1wwDzrzON6DttMzIerS6Tmn6CF2V X-Received: by 2002:a02:8529:: with SMTP id g38mr16979404jai.88.1627317293970; Mon, 26 Jul 2021 09:34:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627317293; cv=none; d=google.com; s=arc-20160816; b=SK5tvb1a6+YJIB1xO/IpUDTUXGbOkDmfDcfz+zDFDLY60cdf40J62r6szOjIqMrS2Z DSH1zr8zgOwYTHCqisA6xbuA3VX9mdOgU9EfTZbkNhtFQLZovSCApKd5jzpyfD+rCp/o tqErssCWZZ9kU8DPnNdHR5zAh0r9pody4iBxmd1r8zolsvz9w74HuoToXIa3QNgJSbaL co/GeuDGJzXATESeNSz2BN79CItM1CjiY2jI76XNv/7085EyOWy0sDw8Jz9si8h0dVqa 6p0evWJtLpJatKrWXdJvvK0SJQ8Qjbz4+hOnjUC/HWSsZxS7sT3W3RJXIx28imWlLxW9 KHvQ== 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=MRFiq3WfzAbCXIcQ6dIFkm9z8pOxp1ulbPgU7pdU0XoRxKMP//a4NrRl7G8hDMZXlt qoYPr+lqRDDwuLPUNf02C9RV1FQL9o8SCUDa6IAkenLSD1JaUCigoqa4o9IeZMMtP1yr 3KVvBED8Fy6PUO06VrI7WwgYDzol4CaRDZ0YPKZguYH8185L69i3N22WgZC8hGJ1GhvD IXsjMHKkru3WXjzq0+B37jqJPlqax/AcrH7XZir+Ak1rFzJfxkXztn1UbDswL/qA6loI Fwt0ZgVxpcrSDLyGgpLV4mhbmEblyV5iEVzyVTgx9pe6JgsWnRNLlPhevDo53SOgglXi mibg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZQxA8oT2; 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 v18si371845ilc.155.2021.07.26.09.34.42; Mon, 26 Jul 2021 09:34:53 -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=ZQxA8oT2; 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 S239476AbhGZPwn (ORCPT + 99 others); Mon, 26 Jul 2021 11:52:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:48560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233395AbhGZPcT (ORCPT ); Mon, 26 Jul 2021 11:32:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9743560240; Mon, 26 Jul 2021 16:12:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315952; bh=KYOiDckllKXj8mHvVhsWCZDPBlWvtcaE6P/Sx14jxpo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZQxA8oT2qzuRlXbAQRuJ2J04wcj8KPH3ffD8c0ygyw9bNk/yYdB81K0F4K8nkuyqN RWcLancXu9L+EU+NHkzkDu5W9imC3Bo9PIVh85mTuLA3MA9+eU9lXEKq3dQ5e1rm/N UrfnHT951AC8fFIexDYwVz1LnMJ/ZmsmcwKrmAzs= 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.13 130/223] sctp: update active_key for asoc when old key is being replaced Date: Mon, 26 Jul 2021 17:38:42 +0200 Message-Id: <20210726153850.506240255@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153846.245305071@linuxfoundation.org> References: <20210726153846.245305071@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