Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp728471imj; Wed, 13 Feb 2019 16:39:30 -0800 (PST) X-Google-Smtp-Source: AHgI3IagQi7hnG4B5bZ6DPZHxR8iBuU1UBuvw0n0w6IbBYbW1fwsLSQSe/uN87Tx6Yl9JDzH+JAq X-Received: by 2002:a63:83:: with SMTP id 125mr932089pga.343.1550104770554; Wed, 13 Feb 2019 16:39:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550104770; cv=none; d=google.com; s=arc-20160816; b=SaeSmF+A5OQHXwsVgEglxiPBWs3KLquxT/rdMX1gw8dGzAz2gjt6ufxekQKfRNtG9B S2MhaZUC9SU5M7pqpmH1QhDNQRrBup5Y0zqavoIHw2Qmpb2cZw7jEnwcTwbG46EKYz58 /ZWf1zWA+/7BFJKdNKTJ2GjUbibJ09DzIUunMi63VSCdPt9vDrl2OFD/zD+GtOvbKq+m dlqOc+XQWl3TBFlSwMFhYFsZNtBqGrK+5gtrvPlKVF4Vpl42QE1KmDLUBVyf0M+R1Jea K0kI/kW0WaPLsKIZpzgSrfrTAHzPT+USKsnsdg1qoN+7QXbKR/TjMNMnXkiNnSJSr1kQ RLqg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MmC9hyvORDvSKiMVfGBQ5FzTLxxuQyAig1qjSeYBRSQ=; b=D1wk3v8HX68QpMuXGU2bSfMtg/6lSXG7N41rD12wjGdZrFoufmlkpIpPRbaex4qgtH XEOGVpOs5Ogxd5DolgC7vjND312hTQOGZV37LZ07F5VNlJOfnwdfNoZjyRFlCb01ofGB LGy2wWidCKLr8U5B1uscZADJ6HGL2u1oi/Ot2APIrUMks5Uo4JvifQw0ce5tU4iyPyk7 I/9+bFoSn62/kO47c+DEwufniw365+5BsrpndWx68QlcoehMeGH50k+X8JTHOS4os59d oEcjM+yxu8sf0AVpg0efDYI8S3WJ3JkRqH8O7E9inpqd6qiWJdtx5PP4SJE8e6uu9sT1 dD/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ynY8dnDO; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u77si950585pfj.139.2019.02.13.16.39.14; Wed, 13 Feb 2019 16:39:30 -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=ynY8dnDO; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392438AbfBMS4O (ORCPT + 99 others); Wed, 13 Feb 2019 13:56:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:38202 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727324AbfBMSkG (ORCPT ); Wed, 13 Feb 2019 13:40:06 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1F6A2222D6; Wed, 13 Feb 2019 18:40:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550083205; bh=yXuLiWmByyPgCYHcAgM/+34pHoS3VqsyYe9dInVwwAk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ynY8dnDOS8fF8eRY+DIUi560NrThqb/Oujt+DDL63DAifI2/2+MeJxCW0jJ3FO99J fiWctbE6bBn8v2OHW4lY1f0I+oamFwb9YXT89FjFYPDJLqlmCFd+abT3j8z3ktqKto R1T7RUDZn7j1fYu9hUs3sqixekJZGAVYkUSGGSeg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+acdeb633f6211ccdf886@syzkaller.appspotmail.com, Ilya Dryomov , Myungho Jung Subject: [PATCH 4.9 21/24] libceph: avoid KEEPALIVE_PENDING races in ceph_con_keepalive() Date: Wed, 13 Feb 2019 19:38:18 +0100 Message-Id: <20190213183649.232203318@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190213183647.333441569@linuxfoundation.org> References: <20190213183647.333441569@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ilya Dryomov commit 4aac9228d16458cedcfd90c7fb37211cf3653ac3 upstream. 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: Greg Kroah-Hartman --- net/ceph/messenger.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -3186,9 +3186,10 @@ void ceph_con_keepalive(struct ceph_conn 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);