Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp474718imu; Tue, 27 Nov 2018 01:22:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/V9nl9GQJSHcaBJ6B8U1yE0FkKFRzv9+mc+kQITfw/pt7phzCXz3QhAyDzoQ8jH4GynL2vG X-Received: by 2002:a63:6b08:: with SMTP id g8mr28293121pgc.119.1543310553679; Tue, 27 Nov 2018 01:22:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543310553; cv=none; d=google.com; s=arc-20160816; b=e4LzPPt7oRTD2IBlV7NRppZA1Y7lBTvkd2jDiWLus/7i75dFhZCfpbcYy+kwwFG/XA yxqLmGsbue5JhAGe3LUlOVYaZpq926uT8s2QKEtdhK9V/s14uORomUw4TxX3GptRdn+c ujJy0K6gEwVi7HngMsAI5U7U/NIvuOlDmPJJGN5urnYgU+WKWjtPjLJxiq0ZR6dpgojG Q8Yx1mGo+8CNtU2WqpKELynLwSJAbZKXFDdqn4bhVFe213C9qdLN29AfrPoooIEyLbFp wPHc2hjcVzk0byINsuFjKqu3Lobj2iVG1LJAlctksPcKzubdipTCjNrAy2E9ttQoz6y0 r1nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=P7d7oRFMpZRZlDmpOo/WNtGhi4hsYq/yW6a+B3n9tDM=; b=kSIJnjMxXiISEMVUrWdidfZ4fExtDreu/LE1DXkl0myna07RpBgtoubL3Y84k2v++w IFF9NTTvcxLR10OlD4vhbSUU4IGi+x1LeO89t8v3nTuMh1muebtReSPsicG3YfvuyFAe uYZkSohH7seGqnJNnhViTrZE90ziO0eYfNrZuq/qZ86d36BE99XkZOx48A4v6tpqXa+e aixAZa4YGS3dfBKMcJcRR1aZ4cYotvc5s3oUgVQjKgKHzU7esHkJzTWi3mKjKXHnDS82 Gby5BrZW8BQux/sR+8Gs1R4bLDhG6YPWEnB578Pv3yPt69AfPOpwo867LV48ArgEIN0H VwQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=egnCOtzZ; 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 187si3585249pfv.238.2018.11.27.01.22.18; Tue, 27 Nov 2018 01:22:33 -0800 (PST) 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; dkim=pass header.i=@163.com header.s=s110527 header.b=egnCOtzZ; 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 S1730163AbeK0USx (ORCPT + 99 others); Tue, 27 Nov 2018 15:18:53 -0500 Received: from m12-15.163.com ([220.181.12.15]:34748 "EHLO m12-15.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729747AbeK0USx (ORCPT ); Tue, 27 Nov 2018 15:18:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=P7d7oRFMpZRZlDmpOo /WNtGhi4hsYq/yW6a+B3n9tDM=; b=egnCOtzZcjXz52iCk8VBMq08h1scOMjhsb tgX5ggP8iUCetDSdqT28o2zKHTjiNXJiC3xeySCSE0zYaT5O6wot7ep0jgC8IEPy q2sgLLadgRJd2PyP2kTEsvyAvh0AjJsjQn18EtiDhZoL8f2+geagZujILuukSACv thxiqr0dY= Received: from bp.localdomain (unknown [106.120.213.96]) by smtp11 (Coremail) with SMTP id D8CowACHjyyRDP1bJXitAA--.6645S3; Tue, 27 Nov 2018 17:21:24 +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 V2] libceph: fix use after free Date: Tue, 27 Nov 2018 17:21:12 +0800 Message-Id: <1543310472-31861-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: D8CowACHjyyRDP1bJXitAA--.6645S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrKr4DCFy5XFy7XF48tw1UKFg_yoWDArg_Za yUZryvgw1SyFWFk3ZFkws8AF4xWw18uF1fGr1fArW8A34UJrsxArs2v34rZF1xGF4UCw17 XF4Dury5Jr1xZjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU0qXdUUUUUU== X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBzxQMclaD0boqxAAAs1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 will 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 --- V2: correct the format of the tag Fixes --- 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: -- 2.7.4