Received: by 10.192.165.148 with SMTP id m20csp4191615imm; Mon, 30 Apr 2018 13:32:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpErHugb8nKyyGCyIa1fKGFZemodAGqN7E911ro4+jAtVrdOHz2emI4JnCTfRvwc1G/bLuH X-Received: by 2002:a17:902:5785:: with SMTP id l5-v6mr13362779pli.379.1525120377008; Mon, 30 Apr 2018 13:32:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525120376; cv=none; d=google.com; s=arc-20160816; b=ieL7vCyQz67fF8PcFsDyKoFz+saD/IZ0hvNvTOpPuwD5SFvNFGOqr7h/+ZNp0KXwdz 1xi630mS6qzsIMOT8gIN3PjNcvBtlOnOsNBapkgIcyoxGckXq5JuIqQvFVkRxEDvcVdu pgt+wJihVf//55mVQY+DXz7BHYIo9Syz2cRq4zbj7DcJcjWhg8hQliZJKFGugdLUWtaX baDFrqxGhub7fY30v7kvuOfSapVnFmOyXToMo8ujpfytBFHAMFZliSKNPNO3F1iNSgcI 68oe+gYcerkk+11TP8sHVV9ZAVnkfiiyCBvEvZatNvOjiYh4Oh8FgUCmJn/5saLdDmmf rHRQ== 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=gS7jFwxLjE8Ya63X/lEQTLoKfEFD49qYA9BZMEhPMNY=; b=O5bDPUvpgPWvkqcuFSH6hC7KUmOHBE5sJvHmte16CHQLevaFAz2k5Dt9iX/Ivxvi2e cXOQxiBq78f6hG245GK2er6eXHKPUGSTBJNmseMmBI+TN7KQV/YUnZHOAPFUSmok5g8j 6b9rEHl0kBuctBKh3qTrLcbbOYqv4kNH3WXn878/xeooHsyXlW2SGPV0GiKF7gEkTVfV OuOdOPGRfpD0eq9CB8NmfdBzA5kVidEr5QF42ylZijHgsNXTYZwWltLVNOJuE7DsC/G4 rWZG0RY9tZgi/O2ZaFdYxGCsFf8PMegfCfXa9uTS2HymG6kONYmG2qvERLUzCX35J05m vT6w== 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 a16-v6si6764373pgn.39.2018.04.30.13.32.42; Mon, 30 Apr 2018 13:32:56 -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 S1755772AbeD3Uca (ORCPT + 99 others); Mon, 30 Apr 2018 16:32:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:59340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755493AbeD3T0F (ORCPT ); Mon, 30 Apr 2018 15:26:05 -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 64F3A22E01; Mon, 30 Apr 2018 19:26:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64F3A22E01 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.4 39/44] libceph: validate con->state at the top of try_write() Date: Mon, 30 Apr 2018 12:24:50 -0700 Message-Id: <20180430190947.889032341@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430190946.093694747@linuxfoundation.org> References: <20180430190946.093694747@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.4-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 @@ -2531,6 +2531,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); @@ -2556,6 +2561,8 @@ more: } more_kvec: + BUG_ON(!con->sock); + /* kvec data queued? */ if (con->out_kvec_left) { ret = write_partial_kvec(con);