Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3764990pxt; Tue, 10 Aug 2021 10:47:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxm2N3jPhPVOfgIm4hakKChcnIto7ud+vl+lqhampcqWYuxxQjubWEN/fcD7E6tYP735nL7 X-Received: by 2002:a05:6638:380f:: with SMTP id i15mr1856974jav.105.1628617648482; Tue, 10 Aug 2021 10:47:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617648; cv=none; d=google.com; s=arc-20160816; b=uCyKXqvcQzlgXhJE240FPyfcoIUSfF9zLvIXXURkatKUcNSV5y7lANIecoebZGilj4 16dqNBHSDeRc5W/Dg/xUL/dukelE44N3R/yNGG51SCN8LEaYfzoP4a1+Bd6lp/CgCCzr K7P5mTsJt6aRe5unhDVZiABU138QbeoK7yEkrXelyuD5hsSvcY8VXkVCLzT2pb1Wf9gf xOIW88ahp9TmJ6Aw1K9iae0lVQgTPwFgcZc3NYvW7KKkvE0wkrznLAxt1gJlJVb3w8Mv zKC6C9xqmcRGHLdxmcFloHTnvch/BMmphAGGLt1QpDXJFkeo3EO3WLS3+4xWxShImjiz vBFA== 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=5mCphfvzr6WKgFLR4iySCSO4VLZv0gW5aFtfongMl90=; b=rN09GXXpQM2xgEAV8HYR0R/34BhB4LiMMOKZmEcA4ZgHpMT3eZFW96UAHYjsDpURbL eGD4sXAiQ866hq3iIQgyGDniE7QBnwsh5y4lGiXRpsRjJ3WIelQfwM/Tki5OYyJM4Mzf g55ETgSiDGQi621hauM24FtZRJWRr3Wc7m2FoWkvEr32rM3YK3YxHP994yRs8IeIHq0S H0ZIkizdZYGTT4nY4a5zzMaagLHUUJq16F/SALW4r4olmCJ9JXBgmUh6+i9bDdIjd6ED w/79TAWe54M3VLxOtqAXpYb7qQJQHIXOVhqAZC/qWwZr0+TVqNV9UIWToGoEAg3rBrDx I9aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=viGM5xV4; 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 q10si24024388ilu.60.2021.08.10.10.47.17; Tue, 10 Aug 2021 10:47:28 -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=viGM5xV4; 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 S236310AbhHJRqx (ORCPT + 99 others); Tue, 10 Aug 2021 13:46:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:34420 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234985AbhHJRoJ (ORCPT ); Tue, 10 Aug 2021 13:44:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 362BD610FC; Tue, 10 Aug 2021 17:39:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617164; bh=aL/VQwDpDgwc8M6Z3IAq8wEXrwsD5+ryJJ/fgRSQzzk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=viGM5xV4QjYjMVFE8+wgu/uhYpy2bqwRJ5R6B/sGN80FCtHBkcV7tnhciNiJyp4pi Vhtt6TKLL/kXlL6Wj1rv9bd9ri7JwdpBuaLuzYnDwX763lgrenbQAD6akD0tLAe4AN 6BPA13xv18s4J4rPczPlG1EkKnegGeYZX+w7WF+4= 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 5.10 039/135] sctp: move the active_key update after sh_keys is added Date: Tue, 10 Aug 2021 19:29:33 +0200 Message-Id: <20210810172957.011233690@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172955.660225700@linuxfoundation.org> References: <20210810172955.660225700@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 fe74c5f95630..db6b7373d16c 100644 --- a/net/sctp/auth.c +++ b/net/sctp/auth.c @@ -857,14 +857,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