Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3710420pxv; Mon, 26 Jul 2021 09:59:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxR9C1Ux6wfX24N9NWj74CxWzhkMJduK30b9Sl1b7tkS7XQsGme08ZYKGzE2t4pgbfFJEoa X-Received: by 2002:a17:907:762d:: with SMTP id jy13mr17675335ejc.211.1627318743897; Mon, 26 Jul 2021 09:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627318743; cv=none; d=google.com; s=arc-20160816; b=mpRZ4qN72B8ZGWh54ZejfTBsB86JMphOMjX9zxsgrYFxFRHIHgTInHaVTzrFVh5gHi l5tD7xHbVVgej7Ng+rV2MVMnLp9xzEZdUXGSx6P8roC4RnzRxUf6G37a66y4GMrObI9x XFtusWLForWD1hIklw3jQIwLDB7uORXDwtUfJgwNVnuYTxn2qPKGZo5uIPxo9xH6QiTL bXvQVjtMiKlP/5fkonNPmqfP7cMMNvcUsHnn/5wqwZJVF8JAkPl1EFbsplNplRMb61Ad upuVhLxyPdjovPMgqx6xYFKBdOqRXkj4WMmkY3LNDl5xuLol+hjl3D5pmVdqj6v+yQ92 22Sw== 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=ULxH5aplrxBaokiDV/u9qWtJhmsGbzTVfiAHGxvimCQ=; b=RSs/CqAM6uHiic5s6QPzWb2KUXQfPY/rGUk/KJL9yyCYIoa4PvxwkP4h+06XBLY/d9 XGpONs8005qJBRs1QyJg8aHozWx7DztshRtetus9itKnAfsqw84j8he9x7NKuBqj7BGQ 2ftaXuPIi9cYvqtpn96XHa300NNUV06fqAfomgtG8UnWhQGRg/R1vtgOHB5JBcbY6Uy1 Ma6F1SHlw2+q6ILW/v585q/91a4SKjqvcLw/uFotOsJZ9hXH9hOG+g0Pvw6pNVOGRrBf 9V66bqezsQ7DrjYi7dvTv7PVP1gluC4Kd00ivsC7o5+MQ2o8kKanbr64aO7ADMFpGyg6 +fmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T1SmmiXc; 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 5si347462ejq.621.2021.07.26.09.58.40; Mon, 26 Jul 2021 09:59:03 -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=T1SmmiXc; 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 S234433AbhGZPdf (ORCPT + 99 others); Mon, 26 Jul 2021 11:33:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:59928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236578AbhGZPTA (ORCPT ); Mon, 26 Jul 2021 11:19:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 532076056C; Mon, 26 Jul 2021 15:59:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315168; bh=wLMu7KGk8CWQSLeDo2XfbK95O2RCPbz5E2x5m/Ka8VM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T1SmmiXcBVoVrLY385h0OXhigBlofbot60oNvnDBWto+YjmTRyX6RfHI0q0dc+HY5 wlHoU+ZetzTgehzkFzBCcDb7ERxlUqCM7x0vi0HVQ5frGa8YuVi2jeHumRvFUFEjq8 7bzEhrPNAs+VZzS3nWbVeJzIF1UjwBYaJeu8cJxg= 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.4 065/108] sctp: update active_key for asoc when old key is being replaced Date: Mon, 26 Jul 2021 17:39:06 +0200 Message-Id: <20210726153833.776008432@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153831.696295003@linuxfoundation.org> References: <20210726153831.696295003@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 1d898ee4018c..7eced1e523a5 100644 --- a/net/sctp/auth.c +++ b/net/sctp/auth.c @@ -866,6 +866,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