Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3927294imm; Mon, 8 Oct 2018 11:49:27 -0700 (PDT) X-Google-Smtp-Source: ACcGV60KtVuBhls3uOC9lDPcVu0dDJicyRRVlc9vsHLxkK8hgQUzMR6dtLhQVwkiM0CJ/5AENtJO X-Received: by 2002:a17:902:9045:: with SMTP id w5-v6mr25787407plz.10.1539024567416; Mon, 08 Oct 2018 11:49:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539024567; cv=none; d=google.com; s=arc-20160816; b=AT9KkGSTqD9X7r6Dx/nfoPdTk9d1CrpjnEklL3fUYlXZ8SNOdWbnX6izXwYnhk5/bh GBge1W07+gKM/uIrQlltalEMH/pfhX8hGSOMh46VwF1nYE6oMXqwoR6Js5kCKZKujQZX U2Mm138MfvWGJYgBA4C8QC4R1lbIi6u/Ye44kFgAqbguqYY0QxQWsU4LVipGZsqwX24V 4yNup3v9oIbdRlNVinFOpbcvMFCWEXYLI9ArhEaEAgM2oQGOjlTYi15Zf+X6iZc7OiFK 2FUxPrd0rPDoo2YAJdP6Ust1Zsn48DbFf0kOiYNSGCjzzLcH0fcY1S6G3CdiTlmoEq/p aphw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=atjvHAQOUTfy4JC5kdu6b5dz+PxLyBGe307z/G+WmoY=; b=f3XT8UpSdeii2V4exoWQ77ZsIm+vTGF9A973hvz/qPWQc6jtApqPYnkFZ5C7KDOejK CSUrN71zs09B4KMHYIpNwmOfvAVuMTNOWrUI0f5K5LEu0X3VNy3x7MX7P6lVm0Rfa1cu /YfTUyM6BRxhHfyrGelrpz1IUt2mS5xYgK+EUGdwWsaC2FN7rEKZ7JYuAoIuqCFOYy1e 4usRQxSntXzaZBZ4mNhpnWuXiSWgFVZeGb6I3ydvFsEsU5Qp60Zh+eE5GdHZaHq6F0Xp bSlxRL02h8ghGYoxcCx2Xqz5LK/v1Xb83Tw+ESIV9Sk1XJQxhG1A9bXCsPaoL/r/mn3i gi/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bE57XVIV; 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 23-v6si16732569pge.453.2018.10.08.11.49.12; Mon, 08 Oct 2018 11:49:27 -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; dkim=pass header.i=@kernel.org header.s=default header.b=bE57XVIV; 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 S1731783AbeJICCJ (ORCPT + 99 others); Mon, 8 Oct 2018 22:02:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:51360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726991AbeJICCI (ORCPT ); Mon, 8 Oct 2018 22:02:08 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (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 672C9214C4; Mon, 8 Oct 2018 18:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024542; bh=D0UgKun6HLGWNIX1WN23TR9gVy4pCUK4zsKu2TWHsT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bE57XVIVarVvL0N4od41M+sgNuTiG2t/HyNzO1qjyW70uqMAhA/7REkIW/F6+mkC8 /RukoBbGSLgi0/4zVT81C/jc11SdgUARWw7DlQfKNX0nbM6REFu6FjPSwqQLrwy1WQ FHkFXNkqb5zLkI0Xyw7MiXPvQ76Z1TZebykoAWuc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+8ab6f1042021b4eed062@syzkaller.appspotmail.com, Ilya Dryomov , "Yan, Zheng" , Sasha Levin Subject: [PATCH 4.18 074/168] ceph: avoid a use-after-free in ceph_destroy_options() Date: Mon, 8 Oct 2018 20:30:54 +0200 Message-Id: <20181008175622.886820917@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ilya Dryomov [ Upstream commit 8aaff15168cfbc7c8980fdb0e8a585f1afe56ec0 ] syzbot reported a use-after-free in ceph_destroy_options(), called from ceph_mount(). The problem was that create_fs_client() consumed the opt pointer on some errors, but not on all of them. Make sure it always consumes both libceph and ceph options. Reported-by: syzbot+8ab6f1042021b4eed062@syzkaller.appspotmail.com Signed-off-by: Ilya Dryomov Reviewed-by: "Yan, Zheng" Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/ceph/super.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) --- a/fs/ceph/super.c +++ b/fs/ceph/super.c @@ -603,6 +603,8 @@ static int extra_mon_dispatch(struct cep /* * create a new fs client + * + * Success or not, this function consumes @fsopt and @opt. */ static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt, struct ceph_options *opt) @@ -610,17 +612,20 @@ static struct ceph_fs_client *create_fs_ struct ceph_fs_client *fsc; int page_count; size_t size; - int err = -ENOMEM; + int err; fsc = kzalloc(sizeof(*fsc), GFP_KERNEL); - if (!fsc) - return ERR_PTR(-ENOMEM); + if (!fsc) { + err = -ENOMEM; + goto fail; + } fsc->client = ceph_create_client(opt, fsc); if (IS_ERR(fsc->client)) { err = PTR_ERR(fsc->client); goto fail; } + opt = NULL; /* fsc->client now owns this */ fsc->client->extra_mon_dispatch = extra_mon_dispatch; fsc->client->osdc.abort_on_full = true; @@ -678,6 +683,9 @@ fail_client: ceph_destroy_client(fsc->client); fail: kfree(fsc); + if (opt) + ceph_destroy_options(opt); + destroy_mount_options(fsopt); return ERR_PTR(err); } @@ -1042,8 +1050,6 @@ static struct dentry *ceph_mount(struct fsc = create_fs_client(fsopt, opt); if (IS_ERR(fsc)) { res = ERR_CAST(fsc); - destroy_mount_options(fsopt); - ceph_destroy_options(opt); goto out_final; }