Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp200080imj; Thu, 14 Feb 2019 18:32:26 -0800 (PST) X-Google-Smtp-Source: AHgI3IaTlF0QhIQJplI6216cC7H9msmTdOpzvBYnAIZZYqGn76IMYwwkFdkO2u/BU/8eORHbfoJT X-Received: by 2002:a63:f148:: with SMTP id o8mr3102242pgk.337.1550197946042; Thu, 14 Feb 2019 18:32:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550197946; cv=none; d=google.com; s=arc-20160816; b=L+71SyhgeluPLJ/vj+PuUG0fY55pOYKTCCSZwvmC4mRaCuWPrQIMNe5J46UP64V4Oe TRYnsj/ayetMcXiq00jFJw32VBM4aoxNHVuwDdVrlxsU/FAOUA9tHxc6awqAr4yi8Cz+ EoLpbJyLI4yk81UYzTT0uOgAD9va+tvGEpR388ZZbnZzH1edZcd4d/XQ4ixJQbYytalL VKfEdPkOx1Mf0EYP5VoV1x3/c/pr87JPzC+bYifODUyRJDlcZq3++8rrPDH81JWn86S4 5w0yPmG36pdUDwrEGShPUV7j+XU3tUtDmqrbqzekzkVv/H7Ip+EakGhqYVHRpuRKdCDE FF9w== 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=3e9t/mDnLyzjuE7EzfElNnWoCKJaLF82dneV7SbvJLs=; b=I1oBPnvdo5u11BgEtCpWYoVwUKpfqDVE9Iia0SOstTQtUwJB9kfcL4wtOKc/rPQpqN b8AFfrSTy+0amqbiG1GXcE8FSPsb0R8GEGm4ZAT6cvubdIOekGwO2ckHaC6RKuFekmTu QiCvKHLWpCoyZs/iZrj0hgamT0EXrBhWMDrar53F+1FD1ucSFnwHsXbvKl2vY5RML638 dC/uNcAZaDSzVGrS1/ogiZHLnDAPgnmZwcabBb1pxNZvnY599dSG6DeKKsb40yMbpzzb 9U9tGYG+pzbaWYR91E2HtWNFHYzOHB+2M2K+6l8ZRl1sKm703dWdLUmjduzDaMD5JFLk AC5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1uoo3T0N; 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 12si4158280pfx.102.2019.02.14.18.32.06; Thu, 14 Feb 2019 18:32:26 -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=1uoo3T0N; 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 S2406124AbfBOCQD (ORCPT + 99 others); Thu, 14 Feb 2019 21:16:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:55536 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406063AbfBOCQA (ORCPT ); Thu, 14 Feb 2019 21:16:00 -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 7632F21934; Fri, 15 Feb 2019 02:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196959; bh=UczYKW/erkCre+95T7mwnlspOqbwiNWsAh9lBazHQ3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1uoo3T0NJ5u7JJ10xlhAaK7HMuKsaoD01jTKNAy/wI2ihL/L7bbS8S+keyQO2ciym gxJCTQigvzXtPagL1W9bxlijvLHqTDBa1E8u9XG5EHBIUDj0bGIqE/Hz0l6kQOkAln eZvsizopAH61vqoJfMnvJ7mXpo0lZGio4Uy3mf8s= 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 3.18 08/16] libceph: avoid KEEPALIVE_PENDING races in ceph_con_keepalive() Date: Thu, 14 Feb 2019 21:15:38 -0500 Message-Id: <20190215021546.179605-8-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190215021546.179605-1-sashal@kernel.org> References: <20190215021546.179605-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 2dc4e064bea3..45bd78f3e28f 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -3068,9 +3068,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