Received: by 10.192.165.148 with SMTP id m20csp4182516imm; Mon, 30 Apr 2018 13:21:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqvB4qV5jEDvd02O9JzhHeGgnK28hxZiXo+yifbFpUCdXMVjk0MqadFkPH45YM8a+3KKOZm X-Received: by 2002:a65:6349:: with SMTP id p9-v6mr11000378pgv.111.1525119709375; Mon, 30 Apr 2018 13:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525119709; cv=none; d=google.com; s=arc-20160816; b=klaLP1fs01QsGITGs+IHv3ddpgI6cqHGiS+l/sCOPOdHk5ZDAXM1KnuKpGtEbN4m6N b/K+DxYJZa16SXjZi2Y6LwTDY5X9qog4wSBkmvmFh77mreQLRTIYnq0soJRr0byZp1hH V+S2h5/oG5Ovugr3s6YT0KoJQh7Loaa2/Gjd65wfsR0ZQvPQjYZeVV1WcYuHFgEUIqy/ pKzCRmaTi4FpRTkobe59k2wQcXbflsa7iuWbEvVAV7hzqu4rPXmlxs1F/Mp9gbXTfzcJ AlD4dNSgkddWfNfMKS8J36cATui1mAa7NfY2MJdDgtw0uORP+YucUEbb7ReOj1K0kqSl 0n/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=JIDOR6CT3XAYOm9hrKyjZChpH60GbP1OE7r+y7fZ6Gw=; b=eybVHSWYfLm+IKQ0tkYV1lwl16nqlaqnDnXVC0XDZYkhcbWBKP/jk2niSfsVckMEcr Rc5Y/RJk/uDgCGdNhX3Ek8DqPiC9oc/G4VlU7gqsH8rvOBvezgw2ZNMys3IBl6W13GkS hK4mZjM6k8wTWTNFK1WCb36w+/wh6PMy1FEtM2zj8r8S5idAI2F9aJqdQqBoHD8hVY/x PkqyUBB4YrvW7HotTGupsehyIhb+PqzLG6XvFHWNabWLqjD1ay+LPIRdhs+ZtfatIrdV vi0+d6h7ncsu/aIfRNNTNuHZEXynQH1ll9zvja2znGQn73lbXXY/4bADMk4dot0J/Rqn ctWA== ARC-Authentication-Results: i=1; mx.google.com; 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 b6si8191866pfk.342.2018.04.30.13.21.35; Mon, 30 Apr 2018 13:21:49 -0700 (PDT) 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; 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 S1755933AbeD3UVV (ORCPT + 99 others); Mon, 30 Apr 2018 16:21:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:60654 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755747AbeD3T0m (ORCPT ); Mon, 30 Apr 2018 15:26:42 -0400 Received: from localhost (unknown [104.132.1.102]) (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 8E99622DC9; Mon, 30 Apr 2018 19:26:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E99622DC9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ilya Dryomov , Jason Dillaman Subject: [PATCH 4.9 51/61] libceph: validate con->state at the top of try_write() Date: Mon, 30 Apr 2018 12:24:54 -0700 Message-Id: <20180430183955.640988377@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430183951.312721450@linuxfoundation.org> References: <20180430183951.312721450@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 9c55ad1c214d9f8c4594ac2c3fa392c1c32431a7 upstream. ceph_con_workfn() validates con->state before calling try_read() and then try_write(). However, try_read() temporarily releases con->mutex, notably in process_message() and ceph_con_in_msg_alloc(), opening the window for ceph_con_close() to sneak in, close the connection and release con->sock. When try_write() is called on the assumption that con->state is still valid (i.e. not STANDBY or CLOSED), a NULL sock gets passed to the networking stack: BUG: unable to handle kernel NULL pointer dereference at 0000000000000020 IP: selinux_socket_sendmsg+0x5/0x20 Make sure con->state is valid at the top of try_write() and add an explicit BUG_ON for this, similar to try_read(). Cc: stable@vger.kernel.org Link: https://tracker.ceph.com/issues/23706 Signed-off-by: Ilya Dryomov Reviewed-by: Jason Dillaman Signed-off-by: Greg Kroah-Hartman --- net/ceph/messenger.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -2512,6 +2512,11 @@ static int try_write(struct ceph_connect int ret = 1; dout("try_write start %p state %lu\n", con, con->state); + if (con->state != CON_STATE_PREOPEN && + con->state != CON_STATE_CONNECTING && + con->state != CON_STATE_NEGOTIATING && + con->state != CON_STATE_OPEN) + return 0; more: dout("try_write out_kvec_bytes %d\n", con->out_kvec_bytes); @@ -2537,6 +2542,8 @@ more: } more_kvec: + BUG_ON(!con->sock); + /* kvec data queued? */ if (con->out_kvec_left) { ret = write_partial_kvec(con);