Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4490364rwb; Tue, 6 Sep 2022 08:13:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR6etMSchZmGkuPC7o0Tkfy0WN6QAX6K+8m1Xx6kOvrUIG1/asI/xdiUSDf9dzH5QlRfW3Cl X-Received: by 2002:a17:903:2406:b0:172:a576:51c1 with SMTP id e6-20020a170903240600b00172a57651c1mr55780638plo.106.1662477200397; Tue, 06 Sep 2022 08:13:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662477200; cv=none; d=google.com; s=arc-20160816; b=vFUJp3U5rqiS3PlJQkJjCMc36kz5bq5xQedOUWhrpA2duSE66pbb9cbROJR0+PPcJx DvwqvlJIUFLlyXoNeeEVwKsexPAdMkJ/NqYOej4aGB5X7NEgNS+2igeg8aw+5fqKMcxL faYj0+owExN2Y1d/eBrq3AB5j0QOsImD+aJGWYZAL4ouH8oNrervTtsLuonEwQB2G0cF JzY5rCA0YrqgovWZMm40DbJQ6q5sl9Pxz9sMW7eF0JNPNvUb4XVB9hcN2WfWqRemmRTr EKvnCWn0wzpklqojr3vBri/LWvomwbTQ0H/0mrrQBUTZI8eq4JRf4bDdOHeAPIOxknqX rs1Q== 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=SnX8pk37c+9ArKQ/x7RHOcYRl1BEyPqqsu8Hj9NNesc=; b=fSzwvo7826GlXhYhrNcPin3msqTrGdp8NxaYcWZy9Neklvif+oqJBB3hF7g4RN9In3 L+nIY0f8HgHovt+cFHb9aoYRWlBWboRf6Q7CzpC1oMGkAzVpQmTwE2EB5l0u7AkRrmJt 1fN8qoqQnjQFgiN21Xm/acs2DQNKKrYb5yx4xmuY92Tz116MDaI9hD9v3bkdrvB2uGFM ZjE5NybsBplkeutksAQPwwpXRPo8nx7dd0Vrd3gsY1vSOUB2dc7BJTIqLe5Q8DabakWa 2CeBSEiKLDnMagzbDaqUBUGvMZAjhNbJ9m9aQ/0aVbKBOnQMghRMfaIO5CJuCS8iSov6 L+ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ItOz7u/E"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q9-20020a632a09000000b00429a769c2acsi4438130pgq.340.2022.09.06.08.13.08; Tue, 06 Sep 2022 08:13:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ItOz7u/E"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S240462AbiIFNc6 (ORCPT + 99 others); Tue, 6 Sep 2022 09:32:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240440AbiIFNcg (ORCPT ); Tue, 6 Sep 2022 09:32:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20E8476444; Tue, 6 Sep 2022 06:32:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1B5C2B81632; Tue, 6 Sep 2022 13:32:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39D3BC433D6; Tue, 6 Sep 2022 13:32:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471146; bh=IzjVCeaCmnUDzdomb3f6ZKlN7CYWqtCZRsxYz91lgBw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ItOz7u/EC7Rfs2gQ4jqdFHI0kLIxTLJoJwv2wChyw+uuMhr87BOiLvmvOxAFr/9ur c6mAsMBWXORJyNwEZQoRl0MNhB3pZSZbOSfWWAUKajk1p6ozlowlybpxRJzBPMGbVg NNegwLdVlqP0rM6KLPFirWG8JbQqT1AhHD8VMpEA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+e696806ef96cdd2d87cd@syzkaller.appspotmail.com, Tom Herbert , Cong Wang , Jakub Kicinski , Sasha Levin , syzbot+9fc084a4348493ef65d2@syzkaller.appspotmail.com Subject: [PATCH 5.10 16/80] kcm: fix strp_init() order and cleanup Date: Tue, 6 Sep 2022 15:30:13 +0200 Message-Id: <20220906132817.615407697@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132816.936069583@linuxfoundation.org> References: <20220906132816.936069583@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Cong Wang [ Upstream commit 8fc29ff3910f3af08a7c40a75d436b5720efe2bf ] strp_init() is called just a few lines above this csk->sk_user_data check, it also initializes strp->work etc., therefore, it is unnecessary to call strp_done() to cancel the freshly initialized work. And if sk_user_data is already used by KCM, psock->strp should not be touched, particularly strp->work state, so we need to move strp_init() after the csk->sk_user_data check. This also makes a lockdep warning reported by syzbot go away. Reported-and-tested-by: syzbot+9fc084a4348493ef65d2@syzkaller.appspotmail.com Reported-by: syzbot+e696806ef96cdd2d87cd@syzkaller.appspotmail.com Fixes: e5571240236c ("kcm: Check if sk_user_data already set in kcm_attach") Fixes: dff8baa26117 ("kcm: Call strp_stop before strp_done in kcm_attach") Cc: Tom Herbert Signed-off-by: Cong Wang Link: https://lore.kernel.org/r/20220827181314.193710-1-xiyou.wangcong@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/kcm/kcmsock.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c index 56dad9565bc93..18469f1f707e5 100644 --- a/net/kcm/kcmsock.c +++ b/net/kcm/kcmsock.c @@ -1411,12 +1411,6 @@ static int kcm_attach(struct socket *sock, struct socket *csock, psock->sk = csk; psock->bpf_prog = prog; - err = strp_init(&psock->strp, csk, &cb); - if (err) { - kmem_cache_free(kcm_psockp, psock); - goto out; - } - write_lock_bh(&csk->sk_callback_lock); /* Check if sk_user_data is aready by KCM or someone else. @@ -1424,13 +1418,18 @@ static int kcm_attach(struct socket *sock, struct socket *csock, */ if (csk->sk_user_data) { write_unlock_bh(&csk->sk_callback_lock); - strp_stop(&psock->strp); - strp_done(&psock->strp); kmem_cache_free(kcm_psockp, psock); err = -EALREADY; goto out; } + err = strp_init(&psock->strp, csk, &cb); + if (err) { + write_unlock_bh(&csk->sk_callback_lock); + kmem_cache_free(kcm_psockp, psock); + goto out; + } + psock->save_data_ready = csk->sk_data_ready; psock->save_write_space = csk->sk_write_space; psock->save_state_change = csk->sk_state_change; -- 2.35.1