Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9258769pxu; Mon, 28 Dec 2020 10:39:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJlp2Oatzy1yi0HGcBqCAJsFXEsMrdpCZTjVr5mTCxWnRttfqUaTg+yNP+UyUPjkt1NgU2 X-Received: by 2002:a17:906:59a:: with SMTP id 26mr42033203ejn.309.1609180771212; Mon, 28 Dec 2020 10:39:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609180771; cv=none; d=google.com; s=arc-20160816; b=Kc6TzHBdp2QMMMOINCgXuwSYqwme55N8iQxo8Yd/5W0yWDPYHy+BxJ6PyqtPRF7xar sHhJ3rZqXABE9nr2TeMy+tYJsc8xL6C4iDoXDo03hmn+kgim53uWDpRfbVWsXKakGWc3 ZFkG7dQzFT2ylfxXfTUMyAO8SJWMvZPZj7d9lrfzwEmY1IQlGYiKircOlQzHwXvKf1WS MykSklWBIBKH34kF13ly7zzSlsq3dTTpiDTdbfi4R1n5llHTjeLjEHj25Wirj23VeVLO ZFa6fVqnOWxSfu/l5/r+HBm1YrVwgZVRMsh5LdR0B7Bo2j2ADk+9Gc4HxUq03oTvLgFW CX9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jXHm8/p90hqPmG0UrKbc5YK5EkAWwWxZJZpwftFcl1c=; b=wM8JzKdVzDPzxLVd6AEdwIL4oAbN9nzB0yC4JGXHWlnUtuTUxn5oVjDQj3aHsh3olk 7aH7f/2ft5mvAqak+QgaMjmBlsYrYs8+um5ZVO8zTAtq7sll8K/XxxhzVfWdMTqTvkxW 0BkfbExoa2a95hQpONlaIkFV3CaVPhkjNy8Lk+/jKWT5pfIOlkANVCcejAwp4Swx1zVI 9QMnUDGAH1ePNuu9kuM4urty0LBj7JZ8idXOBYc0KP4fVkE1CLffbU70cC+6Ywov9+iR +Xn7yDeUhTs8IurYa99BU1CKIvoFz22E04gKmyMvNKTNONFsOBQ1ntSVHT4GMDxVwdad daZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GT4xBe6t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qu25si19081495ejb.146.2020.12.28.10.39.08; Mon, 28 Dec 2020 10:39:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GT4xBe6t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391217AbgL1NiG (ORCPT + 99 others); Mon, 28 Dec 2020 08:38:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:37538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389298AbgL1Nho (ORCPT ); Mon, 28 Dec 2020 08:37:44 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 86CB22072C; Mon, 28 Dec 2020 13:37:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609162649; bh=4t0DZGoAtDWlHD+bQah5pFXRrCGlWDaoHsarHDLTejs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GT4xBe6ty3ulOnzFiloBf5pysiYgE081CGu95bs3sa8Wg9DFSsGOY0rQerQKOtnyx Of2qFtsf20/2IuWz/gCNdIoBhkgAUyf1Fg0oZFvgO2wHyqP+C3Ac9vHdcIzmir4Rkx iG2efil1M/EFU8qwItzyqadO1DypOpE9ialaGrYk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+86dc6632faaca40133ab@syzkaller.appspotmail.com, David Howells , Randy Dunlap , Linus Torvalds , Sasha Levin Subject: [PATCH 5.4 025/453] afs: Fix memory leak when mounting with multiple source parameters Date: Mon, 28 Dec 2020 13:44:21 +0100 Message-Id: <20201228124938.469192413@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124937.240114599@linuxfoundation.org> References: <20201228124937.240114599@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Howells [ Upstream commit 4cb682964706deffb4861f0a91329ab3a705039f ] There's a memory leak in afs_parse_source() whereby multiple source= parameters overwrite fc->source in the fs_context struct without freeing the previously recorded source. Fix this by only permitting a single source parameter and rejecting with an error all subsequent ones. This was caught by syzbot with the kernel memory leak detector, showing something like the following trace: unreferenced object 0xffff888114375440 (size 32): comm "repro", pid 5168, jiffies 4294923723 (age 569.948s) backtrace: slab_post_alloc_hook+0x42/0x79 __kmalloc_track_caller+0x125/0x16a kmemdup_nul+0x24/0x3c vfs_parse_fs_string+0x5a/0xa1 generic_parse_monolithic+0x9d/0xc5 do_new_mount+0x10d/0x15a do_mount+0x5f/0x8e __do_sys_mount+0xff/0x127 do_syscall_64+0x2d/0x3a entry_SYSCALL_64_after_hwframe+0x44/0xa9 Fixes: 13fcc6837049 ("afs: Add fs_context support") Reported-by: syzbot+86dc6632faaca40133ab@syzkaller.appspotmail.com Signed-off-by: David Howells cc: Randy Dunlap Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/afs/super.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/afs/super.c b/fs/afs/super.c index 7f8a9b3137bff..eb04dcc543289 100644 --- a/fs/afs/super.c +++ b/fs/afs/super.c @@ -236,6 +236,9 @@ static int afs_parse_source(struct fs_context *fc, struct fs_parameter *param) _enter(",%s", name); + if (fc->source) + return invalf(fc, "kAFS: Multiple sources not supported"); + if (!name) { printk(KERN_ERR "kAFS: no volume name specified\n"); return -EINVAL; -- 2.27.0