Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp197718imj; Thu, 14 Feb 2019 18:29:29 -0800 (PST) X-Google-Smtp-Source: AHgI3IbpTZbcNaegrq8wQAzUQPYq7VDhM0dURm5kvBV5kTjBO4nqI5ixJMffoXHgO6ovSclVUMGk X-Received: by 2002:a17:902:bd0b:: with SMTP id p11mr7638593pls.259.1550197769597; Thu, 14 Feb 2019 18:29:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550197769; cv=none; d=google.com; s=arc-20160816; b=xjAXC/jgpcf2nJkMpKFOqtCRhaEhKFNMYIMdRRpELXqe4+msaB45RWQFRvMPoNGw0O 3rtstSYzRxd2Un3Cua3jLc12Ddaq023FFgjfyLpx6satAynelWFBiVYPUwUpE1nhjhXp qBtLpwfFOUb2pkQUVpmVEjJI/E+lojPR+HVdbKcK5Zh9HFmNh7ZefNufAzIjNRDvEJVB TCzDG4aZVtXXd3QjO9xDiWFmOvTZhrG0MreuhFI8pPZQHdCA/QkS63V73G+AArs68WBW KgeoD8PfMgfAI70IlxnZXOQvAoRkfNcJxo9OVFRv9nmriaDHKD0fL9TbpwiJpF9NtHKy ceyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PlNpvaqXMeH5AG+yiEDJwTQtr4qDtpM0vMfBAakNlis=; b=P4BoXwsJ/NxJkpTzlgnaz0kf9xeVCeS2oaZS7i2OdSoXyOf2Posf9zSHUG8yexT6Ys JR+tdX9iqmr7guPWRFKRjDXsrwCP4lVc987rLfdSc4QPgezweZdM5QikPp0df6EehiNH WPZvv11g/Txm+r+25wCU29ZMvgnuLiIS5gaUMGYXMlwEpqM84CMeQkqSqbBQH7HRUnwh lVW8bFqLlepesUKH3xCczOlBDQ9TJpAMWETjH8LAXVhA1pLQPGV3JO058FAsPvDMe/kM pz5A3CPGF9MN5vOYkPO0aavCdS3317E3VuA0in5XRKp2mgTSY6W8AQ+uN/pkXoxk0iur FD8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ldlOx5dj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2si3888369pgq.275.2019.02.14.18.29.13; Thu, 14 Feb 2019 18:29:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ldlOx5dj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390146AbfBOCKJ (ORCPT + 99 others); Thu, 14 Feb 2019 21:10:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:50272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390066AbfBOCKH (ORCPT ); Thu, 14 Feb 2019 21:10:07 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3CF0F222D0; Fri, 15 Feb 2019 02:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196607; bh=8yg4XIfnDRgZJz7VkKlmMC7xN9X5nwhQEN6RFf7EJpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ldlOx5djVUniMBh9AeN0YkHUEJOBLFV7J0h6J5NfncV77YYG43hh719VCh/Fss/7Z gCbYvOYzDDLkQ4sMfNVD7gGzNz1sJxjNlEEBcxpYcDsY5pW1eCcHFpIaaCHaN0ObED /63CowxigpKMl7+UstHDQUhdLnTicvoTwUX0qMBY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ilya Dryomov , Sasha Levin , ceph-devel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.20 41/77] libceph: avoid KEEPALIVE_PENDING races in ceph_con_keepalive() Date: Thu, 14 Feb 2019 21:08:19 -0500 Message-Id: <20190215020855.176727-41-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190215020855.176727-1-sashal@kernel.org> References: <20190215020855.176727-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilya Dryomov [ Upstream commit 4aac9228d16458cedcfd90c7fb37211cf3653ac3 ] con_fault() can transition the connection into STANDBY right after ceph_con_keepalive() clears STANDBY in clear_standby(): libceph user thread ceph-msgr worker ceph_con_keepalive() mutex_lock(&con->mutex) clear_standby(con) mutex_unlock(&con->mutex) mutex_lock(&con->mutex) con_fault() ... if KEEPALIVE_PENDING isn't set set state to STANDBY ... mutex_unlock(&con->mutex) set KEEPALIVE_PENDING set WRITE_PENDING This triggers warnings in clear_standby() when either ceph_con_send() or ceph_con_keepalive() get to clearing STANDBY next time. I don't see a reason to condition queue_con() call on the previous value of KEEPALIVE_PENDING, so move the setting of KEEPALIVE_PENDING into the critical section -- unlike WRITE_PENDING, KEEPALIVE_PENDING could have been a non-atomic flag. Reported-by: syzbot+acdeb633f6211ccdf886@syzkaller.appspotmail.com Signed-off-by: Ilya Dryomov Tested-by: Myungho Jung Signed-off-by: Sasha Levin --- net/ceph/messenger.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index 2f126eff275d..664f886f464d 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -3219,9 +3219,10 @@ void ceph_con_keepalive(struct ceph_connection *con) dout("con_keepalive %p\n", con); mutex_lock(&con->mutex); clear_standby(con); + con_flag_set(con, CON_FLAG_KEEPALIVE_PENDING); mutex_unlock(&con->mutex); - if (con_flag_test_and_set(con, CON_FLAG_KEEPALIVE_PENDING) == 0 && - con_flag_test_and_set(con, CON_FLAG_WRITE_PENDING) == 0) + + if (con_flag_test_and_set(con, CON_FLAG_WRITE_PENDING) == 0) queue_con(con); } EXPORT_SYMBOL(ceph_con_keepalive); -- 2.19.1