Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3463825rwa; Tue, 23 Aug 2022 05:18:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR468Z86YPTVmTc4glES7bTsvS1iGePPyHRqGHm67ciKssjp1tkt2lVQWJVuhf+h6K1i6oJK X-Received: by 2002:a17:90b:17cb:b0:1fb:6f83:81a4 with SMTP id me11-20020a17090b17cb00b001fb6f8381a4mr1191030pjb.53.1661257126354; Tue, 23 Aug 2022 05:18:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661257126; cv=none; d=google.com; s=arc-20160816; b=jJ4nmDBWysTqoaEZnZUHxuLFVwRWPN+PNOh3RXm/2Mn+DTAI7IsFhESb3gEu0/aIK5 ldxUDugaVhRUiCZZ+bZWw9gdN1+SvePX6K4BpLTu5SJLmiBNAhcHQaSiImvMhL6VN7Al 0eOME2oXDAhnlKRvKeI62KYZA8sOI1fi1KWNkNkMNFy5eYJki5Nl6HIs6wLqanogTVw4 WliCZ5CjWtMsSSLLkQ5heKzYHWXIYbe4qxFMBbWs54sW7yGES6YhJdCAMPOt0cEnfYmc xDtW8x37zKqZJUcaAuUkktlTVPjud1KF0G0vLmfjqVOb6rFxaGvO3J+Y2HsCJlm/FzzV +j7w== 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=N6OdFT2TudbUbSRK3J3InUX7bm/wLkEqgKKFoE0+/ow=; b=lxX7fcZ+r64Zf7RQzsLfA19xH/BuPLutjwh/6610obBCrO4LBMkv+MXcOzc8l+CXDh WzsEXHAfgjoB+SyrMgZmXf9e98UTXca53x969Q63ZAUBGCzwrffiBOuVEmzXl9B2g1dg CygV58V1hiVPbPlD4WETQgcw+jodx//itKR/sUr5QILdwsCD09CQIrR6L8yt/7tf5TgT kNsrtQ3rLpp66anKgZyJKUeDzh427mfM9BW51KzxMzADuVwjoRNVnyJgbAC0luriSX11 9Cwy9kkWQbaOVzWVSocvLYvi7hJ5fTjGxbINJlNXRJSu7zSU41RaFxfsJZJYTTGF+VI4 yPoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HHxHIztr; 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 a38-20020a056a001d2600b0052d45b66299si16441133pfx.312.2022.08.23.05.18.36; Tue, 23 Aug 2022 05:18:46 -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=HHxHIztr; 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 S243605AbiHWJrz (ORCPT + 99 others); Tue, 23 Aug 2022 05:47:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351930AbiHWJpm (ORCPT ); Tue, 23 Aug 2022 05:45:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB3C32AE03; Tue, 23 Aug 2022 01:43:14 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 102CD61538; Tue, 23 Aug 2022 08:42:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09457C433C1; Tue, 23 Aug 2022 08:42:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244149; bh=6bjpeb1yXqMnkg9+2/fYr7o7Pa+WhVmDu5sIiWvdvEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HHxHIztraFrj8Ir6NBhJq4+GkpWrEZ/89Nxa1ZUVsdP0G1lwfDPUzMp1Lt7JeD+zY htX/J0qwEcdywRvwLoiZI6w/zDmiwQiEQ2drQm4kZj3khbVS33AYsKIjc2QZxPL4Bu cfNtWFWd94L5JJ/eCq9pCzluhVWgGl4tZtHwOPQY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hangyu Hua , Jakub Kicinski , Sasha Levin Subject: [PATCH 4.14 093/229] dccp: put dccp_qpolicy_full() and dccp_qpolicy_push() in the same lock Date: Tue, 23 Aug 2022 10:24:14 +0200 Message-Id: <20220823080057.037313606@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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: Hangyu Hua [ Upstream commit a41b17ff9dacd22f5f118ee53d82da0f3e52d5e3 ] In the case of sk->dccps_qpolicy == DCCPQ_POLICY_PRIO, dccp_qpolicy_full will drop a skb when qpolicy is full. And the lock in dccp_sendmsg is released before sock_alloc_send_skb and then relocked after sock_alloc_send_skb. The following conditions may lead dccp_qpolicy_push to add skb to an already full sk_write_queue: thread1--->lock thread1--->dccp_qpolicy_full: queue is full. drop a skb thread1--->unlock thread2--->lock thread2--->dccp_qpolicy_full: queue is not full. no need to drop. thread2--->unlock thread1--->lock thread1--->dccp_qpolicy_push: add a skb. queue is full. thread1--->unlock thread2--->lock thread2--->dccp_qpolicy_push: add a skb! thread2--->unlock Fix this by moving dccp_qpolicy_full. Fixes: b1308dc015eb ("[DCCP]: Set TX Queue Length Bounds via Sysctl") Signed-off-by: Hangyu Hua Link: https://lore.kernel.org/r/20220729110027.40569-1-hbh25y@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/dccp/proto.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/dccp/proto.c b/net/dccp/proto.c index 936dab12f99f..e552009b6cc5 100644 --- a/net/dccp/proto.c +++ b/net/dccp/proto.c @@ -764,11 +764,6 @@ int dccp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) lock_sock(sk); - if (dccp_qpolicy_full(sk)) { - rc = -EAGAIN; - goto out_release; - } - timeo = sock_sndtimeo(sk, noblock); /* @@ -787,6 +782,11 @@ int dccp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (skb == NULL) goto out_release; + if (dccp_qpolicy_full(sk)) { + rc = -EAGAIN; + goto out_discard; + } + if (sk->sk_state == DCCP_CLOSED) { rc = -ENOTCONN; goto out_discard; -- 2.35.1