Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3757458pxt; Tue, 10 Aug 2021 10:36:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaNjw2+xWLIlLhTZEW/2NYEc+KIqrHeBXXCH0/NJzmHDXHCRfsWk6YaBwAMHAC/UxVykm1 X-Received: by 2002:a02:9147:: with SMTP id b7mr10769041jag.39.1628616987412; Tue, 10 Aug 2021 10:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628616987; cv=none; d=google.com; s=arc-20160816; b=Vtf8ASuPKOj4f2sp5OJihzTTrxCCDuNimqVTwZO0EXRt8+/bpqiN++BKyedoKyChe9 NdE+gvZCFwxV6usLJ0XmbA5R+7me35sYHb3haAwAcmZ9CuTe/AionPq3JS4GPW3+Wpwz NAsa3VHkQdqeZMaiPL88E+IUKqK9DThDIMRicrQ7A/1leE7PCKk/bV09PaZMiYoN3gxj 8Ng0B3+JQ6/sM3dDfNIbbXK52g1QnUKgJ0IINeR8oXUk/qev0ZxMRUTOLovPEa85iduA 5kbIasiJK0sQE4dl/x79OuU3MfXnE69fVdmPKz6WQ9Fwv3KMYmy3rRN2E8G+LdxQWj1/ M6QA== 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=xXGhHdkLcOEMrvkUF1ekDd0lWGu41awfDl/5S+B98ZE=; b=hgKvh7XCLCLGfb0z38+Sdw0AwtxyYN9+Ok2h6mNaJvrZVawPvi/fkyBvEDgpBOt6Uo TSyrDP5GQguOoifjVgbjUid9wL2NlPlpyOtmy4qBLwITCAe85lWi95ItwOScGbCbnQCz BFmkoWuiXbD2nHsTveJrWfl8TqRf+cRJelOPPXUf+QHpJgYs8QFpCf5RV6RXOZbg9THd 5eeG0aiWWXZi83NY62TWvujSNz3Wqn/7P43HDmK0nkWDJQ9q7Us2aZhZvq179CNizMu5 9ze9hAyex8zDujCmwoN/kYH+xx2b5+iArLOfYs4Jj9Nun7rSNSxIUte6ttRC3FtMfYvs Rwwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="sAlA0Gk/"; 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 s13si23746866ilp.102.2021.08.10.10.36.15; Tue, 10 Aug 2021 10:36:27 -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="sAlA0Gk/"; 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 S232327AbhHJReC (ORCPT + 99 others); Tue, 10 Aug 2021 13:34:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:34154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232126AbhHJRdY (ORCPT ); Tue, 10 Aug 2021 13:33:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E3AF860F13; Tue, 10 Aug 2021 17:33:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628616782; bh=nrCmIb4AruyukeULlliE3orbEI85qOJB3L9iiqPuQ4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sAlA0Gk/3MPjTPt96porWn7twO2hMuNXkOZuevPSbUuX3TmigAnKi5norqD2uAhRl 53LbSyOCA2qqFpp0Z5y7+EB7KBleUQdUmDTw+VPImvLxZvR2O0yJ3EvdFHPD12GiMt WMcWVai31m4ewabgVbvl9u03cImLrbkM+2lX7j+Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ying Xu , Xin Long , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 11/54] sctp: move the active_key update after sh_keys is added Date: Tue, 10 Aug 2021 19:30:05 +0200 Message-Id: <20210810172944.557219837@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172944.179901509@linuxfoundation.org> References: <20210810172944.179901509@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 ae954bbc451d267f7d60d7b49db811d5a68ebd7b ] In commit 58acd1009226 ("sctp: update active_key for asoc when old key is being replaced"), sctp_auth_asoc_init_active_key() is called to update the active_key right after the old key is deleted and before the new key is added, and it caused that the active_key could be found with the key_id. In Ying Xu's testing, the BUG_ON in sctp_auth_asoc_init_active_key() was triggered: [ ] kernel BUG at net/sctp/auth.c:416! [ ] RIP: 0010:sctp_auth_asoc_init_active_key.part.8+0xe7/0xf0 [sctp] [ ] Call Trace: [ ] sctp_auth_set_key+0x16d/0x1b0 [sctp] [ ] sctp_setsockopt.part.33+0x1ba9/0x2bd0 [sctp] [ ] __sys_setsockopt+0xd6/0x1d0 [ ] __x64_sys_setsockopt+0x20/0x30 [ ] do_syscall_64+0x5b/0x1a0 So fix it by moving the active_key update after sh_keys is added. Fixes: 58acd1009226 ("sctp: update active_key for asoc when old key is being replaced") Reported-by: Ying Xu Signed-off-by: Xin Long Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sctp/auth.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/net/sctp/auth.c b/net/sctp/auth.c index b2ca66c4a21d..9e0c98df20da 100644 --- a/net/sctp/auth.c +++ b/net/sctp/auth.c @@ -880,14 +880,18 @@ int sctp_auth_set_key(struct sctp_endpoint *ep, memcpy(key->data, &auth_key->sca_key[0], auth_key->sca_keylength); cur_key->key = key; - 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); + if (!replace) { + list_add(&cur_key->key_list, sh_keys); + return 0; } + + list_del_init(&shkey->key_list); + sctp_auth_shkey_release(shkey); list_add(&cur_key->key_list, sh_keys); + if (asoc && asoc->active_key_id == auth_key->sca_keynumber) + sctp_auth_asoc_init_active_key(asoc, GFP_KERNEL); + return 0; } -- 2.30.2