From patchwork Tue Nov 27 07:02:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pan Bian X-Patchwork-Id: 10699789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 532CA14D6 for ; Tue, 27 Nov 2018 07:02:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 427092A98A for ; Tue, 27 Nov 2018 07:02:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 360862A994; Tue, 27 Nov 2018 07:02:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 981712A98A for ; Tue, 27 Nov 2018 07:02:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728902AbeK0R7P (ORCPT ); Tue, 27 Nov 2018 12:59:15 -0500 Received: from m12-12.163.com ([220.181.12.12]:60153 "EHLO m12-12.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728597AbeK0R7P (ORCPT ); Tue, 27 Nov 2018 12:59:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=n4qcQHCUeLmjnPnVLj h/wKr5FAa6bQ0ff11NUi0uUiw=; b=El22LD7oU3p2nJ0h7Y8voiZOxZJlw9au4c 5BlumJGD3bWLvMuQwA6Jn3mxtmnZmmnA7ULGCN0YxETZTcN6ncisNoogC9Co+acT +gn4LLIvE4co9GoR1idff7sNn/qz5lu1SHgYZAIdSzl0e215JeD6X4Ra6Gm4JD66 Z6wyfLsqI= Received: from bp.localdomain (unknown [106.120.213.96]) by smtp8 (Coremail) with SMTP id DMCowAB3uzHv6_xbhguxCA--.15263S3; Tue, 27 Nov 2018 15:02:09 +0800 (CST) From: Pan Bian To: Ilya Dryomov , "Yan, Zheng" , Sage Weil , "David S. Miller" Cc: ceph-devel@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH] libceph: fix use after free Date: Tue, 27 Nov 2018 15:02:07 +0800 Message-Id: <1543302127-14435-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: DMCowAB3uzHv6_xbhguxCA--.15263S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrKr4DCFy5XFy7XF45GFWfKrg_yoWDJrX_Za yjvr92ga1IyFWFk3ZFkws8AF4Igw1ruF1fGr1fCrW8A34UJFZxArs2v3s5ZF1fWF4UC3W7 XF4q9ry5Jr4xZjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUnO6pDUUUUU== X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiDhEMclXlpnhhiAAAsm Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The function ceph_monc_handle_map calls kfree(old) to free the old monitor map, old points to monc->monmap. However, after that, it reads monc->monmap->epoch and passes it to __ceph_monc_got_map. This result in a use-after-free bug. The patch moves the free operation after the call to __ceph_monc_got_map. Fixes: 82dcabad750("libceph: revamp subs code, switch to SUBSCRIBE2 protocol") Signed-off-by: Pan Bian --- net/ceph/mon_client.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c index 18deb3d..05ef5aa 100644 --- a/net/ceph/mon_client.c +++ b/net/ceph/mon_client.c @@ -478,9 +478,10 @@ static void ceph_monc_handle_map(struct ceph_mon_client *monc, } client->monc.monmap = monmap; - kfree(old); __ceph_monc_got_map(monc, CEPH_SUB_MONMAP, monc->monmap->epoch); + kfree(old); + client->have_fsid = true; out: