Received: by 10.213.65.68 with SMTP id h4csp526948imn; Fri, 16 Mar 2018 10:26:05 -0700 (PDT) X-Google-Smtp-Source: AG47ELsmhMiPItuJ+QG/v1eWRSw9bCv0I/qfA7itugEKPNr1P1P7Chz1NxLnCBZKm9QBBuP2JE6j X-Received: by 2002:a17:902:b703:: with SMTP id d3-v6mr2928910pls.209.1521221165076; Fri, 16 Mar 2018 10:26:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521221165; cv=none; d=google.com; s=arc-20160816; b=wrQL97EdhYj8PHHF0f++Ir6gpWWR7w4DEHbbnonvdYJ3uQyIPyuyKlf7/dS1L6tqaH wmBmryQYHIsmAzU8SnDNBtVzXuiVmj3tZl3gFoxwM9uE//2grJoHX8Ny1xTiPc4kWArC Oavhy1m5Wko/FEQmWyooNaKnl3mIr8DQZ1jwimvZM3o8Dl0L7rxNJpJMY5WmCzNf++Lc XZxqx6GC0gPQ8Wd9PKvYaIkQmSelr+VL2WmL3IWzc5iikSEYMcNu0qJNeooY8B/8hbq8 FFN6zC2Ea+ea7rpqesMGl0YfaHh3ooVMsJ96N1V2ywPwoYGxPfQ/TNQWVVnegbuBLZBE dwNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=XvaFnj6Vlo2VXOz7VxXvAhS9LX5aBX62meBJQqKSCw4=; b=ZeC49gGXIWAm6guS+h2nJuv0vsIWPvRKdufYg8avJcuZM+FrONG05YYiB/JIi7QcpI gx3KKsvQIgC2i4taPYWxdTAQbmkXK7rOGYBSuc05OXxm3Y4e52z4CGjGv9QUy/6qauOw bjRYcXewKWV/TMOXJXzd+4fAVZaBhCoZKLT1x3ar8TNIQr5koHXOQ7PiqdAyZmFjncsh gm8A8/tb778w4pvdZQdSuXFjLGmzfZBGChGW7NM90QlwTBXuovgwODTmHPulbDqQrkJi mS1w51HGbLk4yL2/Mb5gdCdnEZdcJgZsJwuQAhBJgjq0QPH75SCMZSK8NaPDBaMMN202 1gcw== ARC-Authentication-Results: i=1; mx.google.com; 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 k80si3039690pfh.137.2018.03.16.10.25.50; Fri, 16 Mar 2018 10:26:05 -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; 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 S933077AbeCPP32 (ORCPT + 99 others); Fri, 16 Mar 2018 11:29:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36130 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933044AbeCPP3U (ORCPT ); Fri, 16 Mar 2018 11:29:20 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id CCF69C8A; Fri, 16 Mar 2018 15:29:19 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xinyong , Felipe Balbi Subject: [PATCH 4.4 61/63] usb: gadget: f_fs: Fix use-after-free in ffs_fs_kill_sb() Date: Fri, 16 Mar 2018 16:23:33 +0100 Message-Id: <20180316152306.663124774@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152259.964532775@linuxfoundation.org> References: <20180316152259.964532775@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Xinyong commit 1a087f032111a88e826877449dfb93ceb22b78b9 upstream. When I debug a kernel crash issue in funcitonfs, found ffs_data.ref overflowed, While functionfs is unmounting, ffs_data is put twice. Commit 43938613c6fd ("drivers, usb: convert ffs_data.ref from atomic_t to refcount_t") can avoid refcount overflow, but that is risk some situations. So no need put ffs data in ffs_fs_kill_sb, already put in ffs_data_closed. The issue can be reproduced in Mediatek mt6763 SoC, ffs for ADB device. KASAN enabled configuration reports use-after-free errro. BUG: KASAN: use-after-free in refcount_dec_and_test+0x14/0xe0 at addr ffffffc0579386a0 Read of size 4 by task umount/4650 ==================================================== BUG kmalloc-512 (Tainted: P W O ): kasan: bad access detected ----------------------------------------------------------------------------- INFO: Allocated in ffs_fs_mount+0x194/0x844 age=22856 cpu=2 pid=566 alloc_debug_processing+0x1ac/0x1e8 ___slab_alloc.constprop.63+0x640/0x648 __slab_alloc.isra.57.constprop.62+0x24/0x34 kmem_cache_alloc_trace+0x1a8/0x2bc ffs_fs_mount+0x194/0x844 mount_fs+0x6c/0x1d0 vfs_kern_mount+0x50/0x1b4 do_mount+0x258/0x1034 INFO: Freed in ffs_data_put+0x25c/0x320 age=0 cpu=3 pid=4650 free_debug_processing+0x22c/0x434 __slab_free+0x2d8/0x3a0 kfree+0x254/0x264 ffs_data_put+0x25c/0x320 ffs_data_closed+0x124/0x15c ffs_fs_kill_sb+0xb8/0x110 deactivate_locked_super+0x6c/0x98 deactivate_super+0xb0/0xbc INFO: Object 0xffffffc057938600 @offset=1536 fp=0x (null) ...... Call trace: [] dump_backtrace+0x0/0x250 [] show_stack+0x14/0x1c [] dump_stack+0xa0/0xc8 [] print_trailer+0x158/0x260 [] object_err+0x3c/0x40 [] kasan_report_error+0x2a8/0x754 [] kasan_report+0x5c/0x60 [] __asan_load4+0x70/0x88 [] refcount_dec_and_test+0x14/0xe0 [] ffs_data_put+0x80/0x320 [] ffs_fs_kill_sb+0xc8/0x110 [] deactivate_locked_super+0x6c/0x98 [] deactivate_super+0xb0/0xbc [] cleanup_mnt+0x64/0xec [] __cleanup_mnt+0x10/0x18 [] task_work_run+0xcc/0x124 [] do_notify_resume+0x60/0x70 [] work_pending+0x10/0x14 Cc: stable@vger.kernel.org Signed-off-by: Xinyong Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_fs.c | 1 - 1 file changed, 1 deletion(-) --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -1333,7 +1333,6 @@ ffs_fs_kill_sb(struct super_block *sb) if (sb->s_fs_info) { ffs_release_dev(sb->s_fs_info); ffs_data_closed(sb->s_fs_info); - ffs_data_put(sb->s_fs_info); } }