Received: by 10.192.165.148 with SMTP id m20csp4167900imm; Mon, 30 Apr 2018 13:04:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqnm9rwe8wZA2AEYOBFsTiC41L3MNihtMuhT357nR8m2LmaGI9padzQy1pkaalEh1qlwp9x X-Received: by 2002:a17:902:5801:: with SMTP id m1-v6mr13848585pli.325.1525118656189; Mon, 30 Apr 2018 13:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525118656; cv=none; d=google.com; s=arc-20160816; b=zEd9MMwv8eTT8P9oKWPsneyLU76dZRpEg6qIztZJQt/xVLJNy3+ZLDmsQhcR6nhvFk J/IKoFf0gPGr3TriN3BJ8+ExQV23X/aK+S2laYHf/249EerSQ8ABBjsVkdLmM2I+6Jiz WFla92uhWj/eFWcvkfyiavgZ8uBQGkQFnki4UlpQCpAHcuIcCXWYUJaEbQ+kIH7aw8sY a1tx8lqCOFvJztbmc7Ovanq3w9oQJ04+Fx85QPaQl+OzFzaIvN5k3Z19enISIk4OmX+e LFfPBzcGmKIDkU3JZ4qv9HHa5DJ85RQOAA52Nh0hveBTEZYB2+5eo6HcUA0A7uiW4ocb gODA== 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=I8819N/Gr086P398h+4fzE67zuzHrcqS21+FwLXmiDc=; b=xEY+8eqqp7QI0Sv7EobQufrZGHNI8BYJgwYxc/I7VGJa67jkUUOoM5DFszfa5gT5PQ bIAGb6eN/42iG6Y5QNRwo6T+wBBtJuF/zw0NfI1CRPenKh+j8kHopt4k5+CEDsTQdkHE I1+PrsV1w41flrRP13Lj/e1oeCe5D4m7LM0ASYw4CsJuccvUwFESZPjOKiaJMxegyNtv hbdtvHjiCAtOhQh83a4kJ91UTnyQGV4E0JQbRPW0RPu9Mlr6L2fFC+j7dDZYd6ZbfUl5 eadh1CD9ysnj8QpfJIPfbyDxW68JBmxB7RpufZeMd+eC//TV1q7p6Uei1Jb39GMGmSmX aCOA== 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 v2-v6si6543381pgf.75.2018.04.30.13.04.01; Mon, 30 Apr 2018 13:04:16 -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 S1756170AbeD3UCm (ORCPT + 99 others); Mon, 30 Apr 2018 16:02:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:34324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756007AbeD3T1g (ORCPT ); Mon, 30 Apr 2018 15:27:36 -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 0410322E01; Mon, 30 Apr 2018 19:27:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0410322E01 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.14 75/91] libceph: validate con->state at the top of try_write() Date: Mon, 30 Apr 2018 12:24:57 -0700 Message-Id: <20180430184008.182097707@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184004.216234025@linuxfoundation.org> References: <20180430184004.216234025@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.14-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 @@ -2530,6 +2530,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); @@ -2555,6 +2560,8 @@ more: } more_kvec: + BUG_ON(!con->sock); + /* kvec data queued? */ if (con->out_kvec_left) { ret = write_partial_kvec(con);