Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7495197imu; Thu, 27 Dec 2018 22:35:43 -0800 (PST) X-Google-Smtp-Source: ALg8bN51BoHj/bRV5AU/NTKEOgS9kybfNxBCf9jIViHiVI2qnyLbW9XcYgx16MptkRci2dDpci8U X-Received: by 2002:a63:e40c:: with SMTP id a12mr25438280pgi.28.1545978943285; Thu, 27 Dec 2018 22:35:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545978943; cv=none; d=google.com; s=arc-20160816; b=CBb/jHhLNfVndrYceK7DRyzLXjeRDAoetfR8j7r41CYa3JK1xBvecXCW+uC+FdVPXY Bf0B22my7pMAITNgpkNt9yvkuKsTEDGd3gUgtzLT13eaZp1HIFYORDeYS1fKTe+sgVxm m7XJyf8NeaKsvWZKEejNQyDnQ7TJh3NL6KINdCX7IpIgDnu3yqcl2eIwNiJnMQTNoxxq VdlkkMH9eNu8iJv7NCchkym6Ih5PN6iZFzX5kSJmU7UzBLL3ktxbJ6wUBW9bvMSmeIRu ZKyc4N2ZN8duGkI7zYixxWvaB3bdsxeiHEQVewcyn9ObvrDDccyQ9B2/kwFo6+iDIIxw +qww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=wMtxKrlb5S1b05ezaTrpeU8MfFOhOA1dgmWDjaTi/nI=; b=vcz37BaTUjq5pHr+2pzykOxIXSnkf47zvHDoJbSttzYdY3SUo59CBnoqiDr2qPbXfY 4lBFaOkO4iBhsDvRVzwrMHMlH6fX8l8pwcUNED4RiC2wQfFXCp+O8wnHVxuf/IJr/1iO 3DbLF0QpBG9+PKPqsf1e3j6t3a3IYieGGRS8MExhoSbsSYXalEQKrgp+2cS5Qq7gM/Hg Ts1E1qO5Izr70ZvqxWjluDgNNa7+SmSzAU3/OhnLl1pY2qD2SffYdca3Y9tBCfJ7ByBV b9rR0EgvGerLohfIFyfXtG6CE9qtFHtvtgRiSIhypmGfZ89LDgz8v0cJoVEgBd/3Bgxp tEHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fVFqSnlt; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c81si277396pfc.82.2018.12.27.22.35.01; Thu, 27 Dec 2018 22:35:43 -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=@gmail.com header.s=20161025 header.b=fVFqSnlt; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728828AbeL0TIv (ORCPT + 99 others); Thu, 27 Dec 2018 14:08:51 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:45353 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726466AbeL0TIu (ORCPT ); Thu, 27 Dec 2018 14:08:50 -0500 Received: by mail-pf1-f193.google.com with SMTP id g62so9467820pfd.12; Thu, 27 Dec 2018 11:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=wMtxKrlb5S1b05ezaTrpeU8MfFOhOA1dgmWDjaTi/nI=; b=fVFqSnltiUJWepUCnVR8ikfY7a2hruf1LVSk6b548JWRgrN3LjFdxkPrkITkWBAgMt Rs2ZH1KlxSBtFP3/aqN4mVC85e2O+1Mu2chJGk9fR77yKI/jKcUDp8301BDd3ggvjc2g /tPHPIebZbDdR02b1oaf58OCVUeB49VpTsZdabKv+apjBGbTvtaNzfjUaLH2mZ4q1PO8 1F5JcWXvomE7xdV2isjdmvy8Rj5wn7JTv/+RMFIoz/gtuzzXTT7OJSLUtisCOzyfTnzq APRxiteRbHbPDCZGCvgOMYnzLgNZ3itEQgGTfuMVtVEbLPrUi3vL2QDGseE03/t5TKWV gzIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=wMtxKrlb5S1b05ezaTrpeU8MfFOhOA1dgmWDjaTi/nI=; b=pbVPCuw/wnyjXuw9tgnPgjzxgXNRItHGVoty1IJmKtqMaBsTl5jkPuyhBoqSm5ZcoE Q3RhOZMOpJ68v7BfO4IMFqFDpEneibgo0c45FtScGEmDMFm1b46+V4FTgWIqePPzNipF Og1+Ivzl74w36UcML54NgG9YrtLC9y74KI0Me/ZE/xQuw6eoMepwnZhDyhUk6CwTtqdm nN3Yjy8Huji0L/LiWyvXSWlYFoHUGB8ul6MpiZFDLggjWh8Q0Oo0sPwle/mmKcUKvxza qaG22CiukZrBImrB+yLdW7O4ugl2D4pfj2vGyhYZuHA4Z/QYagbc2mbYyc7ewY7Ao1y2 BMSw== X-Gm-Message-State: AA+aEWa4vepPOUqwqHraopLoYb22HB6rRvpGF6sx4Oh6meKEmtLyzkAm eKaUkR2fmNcM88JrWXhzXT4= X-Received: by 2002:a62:1b50:: with SMTP id b77mr25426045pfb.36.1545937729622; Thu, 27 Dec 2018 11:08:49 -0800 (PST) Received: from myunghoj-Precision-5530 (cpe-76-176-3-80.san.res.rr.com. [76.176.3.80]) by smtp.gmail.com with ESMTPSA id d69sm51982409pfg.168.2018.12.27.11.08.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Dec 2018 11:08:48 -0800 (PST) Date: Thu, 27 Dec 2018 11:08:45 -0800 From: Myungho Jung To: Ilya Dryomov Cc: "Yan, Zheng" , Sage Weil , "David S. Miller" , ceph-devel@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] libceph: protect pending flags in ceph_con_keepalive() Message-ID: <20181227190842.GA19565@myunghoj-Precision-5530> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org con_flag_test_and_set() sets CON_FLAG_KEEPALIVE_PENDING and CON_FLAG_WRITE_PENDING flags without protection in ceph_con_keepalive(). It triggers WARN_ON() in clear_standby() if the flags are set after con_fault() changes connection state to CON_STATE_STANDBY. Move con_flag_test_and_set() to be called before releasing the lock and store the condition to check after the critical section. Reported-by: syzbot+acdeb633f6211ccdf886@syzkaller.appspotmail.com Signed-off-by: Myungho Jung --- net/ceph/messenger.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index 2f126eff275d..e15da22d4f37 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -3216,12 +3216,16 @@ void ceph_msg_revoke_incoming(struct ceph_msg *msg) */ void ceph_con_keepalive(struct ceph_connection *con) { + bool pending; + dout("con_keepalive %p\n", con); mutex_lock(&con->mutex); clear_standby(con); + pending = (con_flag_test_and_set(con, + CON_FLAG_KEEPALIVE_PENDING) == 0 && + con_flag_test_and_set(con, CON_FLAG_WRITE_PENDING) == 0); 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 (pending) queue_con(con); } EXPORT_SYMBOL(ceph_con_keepalive); -- 2.17.1