Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1803101rwb; Fri, 12 Aug 2022 07:08:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR5N1UEzOvpGh2ruhj1/19ypaiVccTPfCzx7T+j96g9M6Q3V0xVSxE9n4Oi8d7wTukDi9/p5 X-Received: by 2002:a05:6402:e98:b0:441:a982:45bc with SMTP id h24-20020a0564020e9800b00441a98245bcmr3674173eda.239.1660313305886; Fri, 12 Aug 2022 07:08:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660313305; cv=none; d=google.com; s=arc-20160816; b=Rvt0l8Oa7bjijeJHNuDx+kNdiyIgAsqeG8bbt4tlWaYkNI6rH61pzwCuaiHXATZ60D rWVgsz+rTQDICQsHiEVPvJn3JZcZ0qULU8KrlgBdOKOqReHgUt5ASus4kAt/9HR/X+WX Zvx2Rt446fO7LBd2ZzrSEgZnOxP9lXAkSs7FcrMEsbOZxobUPlzCi+l5VeZfnvamCSWb Xdtp9CSLl2Han1fliKQzLqZBElOXhtQmXq6YeWzhvXpZfF92woEugdn//hQyuycKyDH9 r/6xc5TRyrNWaK4GqsUfah9KFkpymfmFL3LLIyD6hSobZdAZ4vTXZFnjjrlk7H0T85AU ge4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=duolXcn7gQG7XKIBN9ehMYZsLClpDQ/6ICkqLMlWWbE=; b=bOljfnv3e2WZNzlG5MBb4tlpTcUv1DB97Re4mT6i0dT8aT8ml2kKbrSdUlQmKEvzbe 9eaIk/VlVLxgfiU+GYDAN56ubDCI4yp4JVsgE4qbkVLq1FHCiF8xppBPC6wmhdPkVNkF obzy7WDh50xcr6XHwHsrcAsJEoVN0TgmGErjrXzrQApOZxPrxPtjhsUV4IB8+qKhfbEj tZWSyiTF+wcWhdHIT7YKAr4U0ZsVTfnLZqkZc2dgQv41apUwUYdppLHg18gB+b9DnGkz LfYZFv1nTm0t38tsRo+iaOfozqauIJytj7zhviXRvU5qUkZS87elaIdCPm9NFxPx6YSQ 6C8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=KW4gMJdG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr24-20020a1709073f9800b007316843d58bsi1915676ejc.925.2022.08.12.07.07.59; Fri, 12 Aug 2022 07:08:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=KW4gMJdG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238738AbiHLODU (ORCPT + 99 others); Fri, 12 Aug 2022 10:03:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238692AbiHLODS (ORCPT ); Fri, 12 Aug 2022 10:03:18 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0EA3A2866 for ; Fri, 12 Aug 2022 07:03:16 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id x21so1474074edd.3 for ; Fri, 12 Aug 2022 07:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=duolXcn7gQG7XKIBN9ehMYZsLClpDQ/6ICkqLMlWWbE=; b=KW4gMJdGbWo9mDn74e4uTWIobzc3VGOXPPZe1gFA2raZ+rOgwf/DtjkHiiLIVJ3Qa1 CHS42qQEYDwJYGXXQbn08sSnjm/yhJohRtE2A4luI5pufE+/p0dh+mTVCyL6U0KObtRq YRUhPr7ToxVNmrPzF2pJJHu/KcubDC8NdyW+2ONVFsDN1qRAtID8EEhDZUR8xKqLBIOv sv8IZSQ8iuwK4xsR3X6VLzxr1VzYF8jm0D3taPxzxXiGMRVRhuUy8wKV+Brb8NM7Ttfl qy/5y9nU2lt7AKclWTrHQCDC4Ryt2gKtreXYqaiShmzNgl4zixUcqTOxYpQhB/735FHw 2rqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=duolXcn7gQG7XKIBN9ehMYZsLClpDQ/6ICkqLMlWWbE=; b=TSM1osFs8Wh5/P2PjiBXQ2KAtfVtoJj5prYDVkIAyR9fbMZ9El6UICYpUESRdugs24 pnJgYnuNGCLFoaKgPLlShwGuvu8VaVfofbLJfNhV9T2SrhgAkQwCItMAG3A8AjKZB69F cAWLRvq+RpLrnsPdrxv61moPtX2xw9PtWazMTL8nkOPg5/E/NtmiVaRdVq6U3Db25VAT HmepPoPUSgoW6qVun3ffvpS3SwVcrmYo/AsPSHd5I7qelG6sGQs1pocCUKX3qNC3L9Fx uZHTzoS69nTqLjdkAu45bMoGwkZp3ZPz1duNqI4M19FH10aPliJguL93SL9zcfB33VZn 3DTA== X-Gm-Message-State: ACgBeo0nnATmyOp8wpw4F3J/yLZHIQZ7QvIPSuGZOdqLwJ+Nj8lSLFqv IbQQ+HNRb9kaO/mTbAOSt6SZ9zYjVVk2ov3aQ8f63imRoRSMjg== X-Received: by 2002:a05:6402:268a:b0:43e:84d:c5cc with SMTP id w10-20020a056402268a00b0043e084dc5ccmr3782168edd.372.1660312995388; Fri, 12 Aug 2022 07:03:15 -0700 (PDT) MIME-Version: 1.0 References: <20220812132124.2053673-1-dzm91@hust.edu.cn> In-Reply-To: From: Dongliang Mu Date: Fri, 12 Aug 2022 22:02:36 +0800 Message-ID: Subject: Re: [PATCH] drivers: binderfs: fix memory leak in binderfs_fill_super To: Greg Kroah-Hartman Cc: Dongliang Mu , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan , Kees Cook , syzkaller , linux-kernel Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 12, 2022 at 9:56 PM Dongliang Mu wrote: > > On Fri, Aug 12, 2022 at 9:41 PM Greg Kroah-Hartman > wrote: > > > > On Fri, Aug 12, 2022 at 09:21:24PM +0800, Dongliang Mu wrote: > > > From: Dongliang Mu > > > > > > In binderfs_fill_super, if s_root is not successfully initialized by > > > d_make_root, the previous allocated s_sb_info will not be freed since > > > generic_shutdown_super first checks if sb->s_root and then does > > > put_super operation. The put_super operation calls binderfs_put_super > > > to deallocate s_sb_info and put ipc_ns. This will lead to memory leak > > > in binderfs_fill_super. > > > > > > Fix this by invoking binderfs_put_super at error sites before s_root > > > is successfully initialized. > > > > > > Fixes: 095cf502b31e ("binderfs: port to new mount api") > > > Reported-by: syzkaller > > > > Where is the specific syzkaller link for this report? It would be good > > to reference it so it can be properly checked. > > > > Also, how did you test this change? > > I found this memory leak in my local syzkaller, and there is no any > syzbot report about this crash, therefore I use such a Reported-by to > indicate. > > Although my local syzkaller does generate any reproducer, this bug can > be triggered by injecting faults at new_inode and d_make_root (i.e., > between s_sb_info allocation and code after d_make_root). > > > > > > Signed-off-by: Dongliang Mu > > > --- > > > drivers/android/binderfs.c | 8 ++++++-- > > > 1 file changed, 6 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c > > > index 588d753a7a19..20f5bc77495f 100644 > > > --- a/drivers/android/binderfs.c > > > +++ b/drivers/android/binderfs.c > > > @@ -710,8 +710,10 @@ static int binderfs_fill_super(struct super_block *sb, struct fs_context *fc) > > > info->mount_opts.stats_mode = ctx->stats_mode; > > > > > > inode = new_inode(sb); > > > - if (!inode) > > > + if (!inode) { > > > + binderfs_put_super(sb); > > > return -ENOMEM; > > > + } > > > > > > inode->i_ino = FIRST_INODE; > > > inode->i_fop = &simple_dir_operations; > > > @@ -721,8 +723,10 @@ static int binderfs_fill_super(struct super_block *sb, struct fs_context *fc) > > > set_nlink(inode, 2); > > > > > > sb->s_root = d_make_root(inode); > > > - if (!sb->s_root) > > > + if (!sb->s_root) { > > > + binderfs_put_super(sb); > > > return -ENOMEM; > > > + } > > > > How did you test this change to verify that you are not now just leaking > > memory? It looks to me like you just changed one problem for another > > one :( > > As mentioned above, I just tested my change by injecting faults at > new_inode and d_make_root. The following is a reproducer I extracted from syzkaller log. The fail_nth needs revision according to your own environment. syz_mount_image$adfs(0x0, &(0x7f0000000180)='./file0\x00', 0x0, 0x0, 0x0, 0x0, 0x0) syz_mount_image$afs(0x0, &(0x7f0000000040)='./file0/file0\x00', 0x0, 0x0, 0x0, 0x0, 0x0) mount(&(0x7f0000000100)=@nbd={'/dev/nbd', 0x0}, &(0x7f0000000140)='./file0/file0\x00', &(0x7f0000000280)='binder\x00', 0x0, 0x0) (fail_nth: 40) > > Can you explain more about "changed one problem for another one"? I > don't quite understand this statement. > > > > > Please always be very very careful when making these types of changes, > > and verify and test that they are correct. > > > > thanks, > > > > greg k-h