Received: by 10.192.165.148 with SMTP id m20csp4147015imm; Mon, 30 Apr 2018 12:38:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrVHrxKyHUYRGvy3vfaBoAajURV/RxaaIES+kDTz5PUfLQOBSm2yWc3a5tc121BxWpRxSc/ X-Received: by 2002:a63:2bc4:: with SMTP id r187-v6mr10289842pgr.231.1525117120794; Mon, 30 Apr 2018 12:38:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525117120; cv=none; d=google.com; s=arc-20160816; b=lxJRixpVoDSLmuVCUrCzZ0GfTw2h6sa4xK8+GznWNkhbB0hu/4/sgDNqo88indJdUN 9ChP9RAYFXkCcemQJ9cdP+k00acjgzml+JS2TzDzX/UVV6BiMwA4j/n8K3p7czUj0Cso c+0OKxTtQaxHa967YFgHiJxvxvAmVw8g1ff4M1da+8kZ5Lne0RY/R0P8K7grQ/NmfNqW Du4dF8s9CxcpuosiIW6pWXIiexVIvXnq3J4m4Mf4pl0L816z/hXQ6bE6qD+yJdGejqRX ObOJVVc8xbCsVYU5LYzeLuMShxLv3nOcKFU7j6Qb+zQMm7TX6qBBrmjFTs5EWjN0+UDD VnYA== 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=zbC4IGvYmgwKkH/ngQP8PZl8nBt1Y9ac1DYr/6RgArk=; b=Zk65Y6sYA9duXKdfJVbc4yy59GPmGi1zhEZuPHIf7z6Lg+e9Z09ZISrRpIurDJWsyM CIyVMqTqDY2cC4DN5cV+OZa58VDatcChSB5oBlaYa6uf6JptAxctfz9bIFTvfwxJIyvO yavyM+lQTBuiFFCUyIbUatQXi72AplP6pwMu76LCAI/Tx0QcGNas43Y3yGHF6nXlv6go vGClp77ire7Kl25C0H62V0FHe9ZQhHkCpVrZgOP5020p3IKd1eEfjAwDDEIM1zSuD1Qk t3oHl49RjfSP7IdJNbE2zPlMgDGOAoWnx9rAMAxI5Z2Fzm5QLxFRamtyfTiz0SUTa8Rw 8aPA== 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 l11-v6si6557929pgn.315.2018.04.30.12.38.26; Mon, 30 Apr 2018 12:38:40 -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 S1756463AbeD3TiQ (ORCPT + 99 others); Mon, 30 Apr 2018 15:38:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:36668 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756387AbeD3T2l (ORCPT ); Mon, 30 Apr 2018 15:28:41 -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 34D9222DBF; Mon, 30 Apr 2018 19:28:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 34D9222DBF 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.16 088/113] libceph: validate con->state at the top of try_write() Date: Mon, 30 Apr 2018 12:24:59 -0700 Message-Id: <20180430184018.914737228@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@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.16-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);