Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp514240imu; Tue, 27 Nov 2018 16:23:58 -0800 (PST) X-Google-Smtp-Source: AJdET5eJDdyZ5+KSVdVwIBZzkP3Vl+/l06nlQt5tFHuAeqDvV0E/O8lEjwNAFumSw+w/zoGzTP2t X-Received: by 2002:a62:848d:: with SMTP id k135mr34588105pfd.47.1543364638417; Tue, 27 Nov 2018 16:23:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543364638; cv=none; d=google.com; s=arc-20160816; b=BnEBkn5GWdUlH7i7onNy1E538B55Rx9Vqg6Y1oM/+g7FvS+NUGZoJov3FgszaM4Ye4 ffm3sQoYBJoOKOy2m+qTVYx2TIHgcPptGRkGivDXvhiCvselGOk5EP/UUmIzfeGy5RPd yCYQTJVYRJ4+X2QyF2vwNYZ0yOEc0IK0HXgZotWbXyc6o87MoXoCzexl/3DtCyPK5/zI wGj0I4nU+GDavyjL7eMDqMjhx8sYw7iSppsXLLaoEIQz38vkG01PRfQXu98iVi4IjiU3 gQpCOy39jomvjYqGvGbOPU3M/ZgV0qqySeygSARYhownX2fpMpKV6RLXdmE+EzdEistq U6KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=UrLL+9QTj8uhVVoUAxVSxOzu5I9ezaM0pm9Gx/ykTvo=; b=SC+iBE8ioXvE3tUaKC51jksImrUyie6qEqM+3UbCGDIggWCE/eLucKUls75dRdHQZF 94Izaul2ZUk3vahBsXgIhKrGl7q3VeLxTXKgmegtTBBVf8sEH3OfavnW7Z7O2JDzNfnx tXd8MO6CNFbei7fjJvvVvUJm0mS+EsMqhXvdlQA5oPPcDhvw5/4H8tZ1Vec6iS4Q0VNb xQho+aV0GO6/6i9sR+jnJ3t5oKoTYm11rLTbAJZXmIikKYcBm0v3LxTgMuCkGkRCXu2m Ql44Hb1UvnYpnRHAIlHhqZLvO88SW5xLDDmIBkZ6KrkQmxWkxLc/bWLNRKDVmka/nxpE nPvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=d573jxsi; 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 n5si5414832plp.294.2018.11.27.16.23.43; Tue, 27 Nov 2018 16:23:58 -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=d573jxsi; 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 S1726841AbeK1LWn (ORCPT + 99 others); Wed, 28 Nov 2018 06:22:43 -0500 Received: from m12-17.163.com ([220.181.12.17]:44092 "EHLO m12-17.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726418AbeK1LWm (ORCPT ); Wed, 28 Nov 2018 06:22:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version; bh=UrLL+ 9QTj8uhVVoUAxVSxOzu5I9ezaM0pm9Gx/ykTvo=; b=d573jxsirO70Eqn81c4Fw n9idpvBjlSLd4gqYAUF96RzwsccvQgOrCx2SA0oKiAeA+cwZ7YAKaiwpeC8+PX6j h+V2evMagXfYGbx7B/z3e6IQyWpFWzKdIv5lRclwstp0JlZ56gAuRT7WucHCNKaf RzkYFkcdkpGmKAU/xFKY6A= Received: from bp (unknown [106.120.213.96]) by smtp13 (Coremail) with SMTP id EcCowABHp3ff3_1bmZmeBw--.48468S2; Wed, 28 Nov 2018 08:22:55 +0800 (CST) Date: Wed, 28 Nov 2018 08:22:57 +0800 From: PanBian To: Ilya Dryomov Cc: "Yan, Zheng" , Sage Weil , "David S. Miller" , Ceph Development , netdev , linux-kernel@vger.kernel.org Subject: Re: [PATCH V2] libceph: fix use after free Message-ID: <20181128002257.GA38329@bp> Reply-To: PanBian References: <1543310472-31861-1-git-send-email-bianpan2016@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-CM-TRANSID: EcCowABHp3ff3_1bmZmeBw--.48468S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ww1ktr4kWF18Aw15tr1DWrg_yoW8Gw17pF Z5GF1jkay7u3WxWanFyFsYqF18CwsxtF47Wr4UCF1rKF98Wr1rXFW0ka90gFy3ur4xJF1v yrWxtay5XF15AFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bUtC7UUUUU= X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiQBMNclSIYU1-ZwAAsE Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 27, 2018 at 11:17:26AM +0100, Ilya Dryomov wrote: > On Tue, Nov 27, 2018 at 10:22 AM Pan Bian wrote: > > > > 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; > > monc->monmap is assigned here. It's not obvious, but monc->monmap and > client->monc.monmap is the same pointer. > > > - kfree(old); > > > > __ceph_monc_got_map(monc, CEPH_SUB_MONMAP, monc->monmap->epoch); > > ceph_monmap_decode() returns the new map, kfree() frees the old map. > I don't see a use-after-free here. Got it. Thank you! Pan > > Thanks, > > Ilya