Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1546949rdh; Mon, 25 Sep 2023 16:55:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGECZRsLWb5tg3PltVPATtkOY2MOSWVtuzxMRrG1YNz/JpqIqkhnJZVQo2UHOPtJ/FinCZ7 X-Received: by 2002:a05:6a20:442a:b0:15e:b253:269f with SMTP id ce42-20020a056a20442a00b0015eb253269fmr1612621pzb.28.1695686154179; Mon, 25 Sep 2023 16:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695686154; cv=none; d=google.com; s=arc-20160816; b=yzx+ugMlieWkMN2jRal+QXjM6bzrj3TbbHc+l23lSVBoIWJBclGk+o5vvFHUDfKgPI rLzxQr7D8ge+3l5kf8dKPwlkX/ePcfq849VnyV1baKwSg7HyjlXbY04OYpe2GOHIW0m+ B30XmB6OKQ9aO+vJ1Rvi0ybJ+uUymbC8HDlrEpBywLeOPDMzT4OCi0AW6qBREUoikpTP MvdQlX7aOi098BzOSt1aSCumusuu1dfekYMQ62+HlvDoLwMeAPmueGjcFrUhxn3ZZr3w WwtfH6tMtyFpRJg3QtoGi4OUeBOEnahiA0OKA6Hy6absoHjuTzQ7VvQ1NefnwGBLZQoz ESvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=cIe77vdqpeQpP4qLU2XoNxMwUlYUlcq3Ovdt56o2n9g=; fh=iQ7OShXqxcNWGJ0Fnz4oIQABSyu4oqWsMHWwg31qb78=; b=rJrFjrqk3CjDHexKSTIIiiaGZHPpUS7msMwH234p0p2Baqw/ITKPB0p6znUKCEYAU8 GwFiNYh9pdvRw2/22LjWAIA+9yrUmGf0nxCYvUbJ+TKvf5tyiEpGjv+AyEsP3CpS0Jj1 szpCzXO2xFURbfatm6cCxt/KUN1nWqVzLZ04gtXTFXgNnj/R4ZV0Kl/eldZ4Mvjy8TFc Di3yrDwcErU/AispGNVCQB5VCoBH6oG+PjkR5pcjgM41Zt6jSdAlvVizL8d3yTiFVZ11 fZIdDUtW3M/bLi6yeW7hYWNG8Qsmyyvno5L9yDe7ZqpmZT/EhBqBk68JulUo+0knXWwL LG4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IX3s4sxa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id l11-20020a65560b000000b0056951c32d80si11651858pgs.556.2023.09.25.16.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 16:55:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IX3s4sxa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 0E85880BB6F0; Mon, 25 Sep 2023 11:47:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233252AbjIYSrH (ORCPT + 99 others); Mon, 25 Sep 2023 14:47:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233132AbjIYSrF (ORCPT ); Mon, 25 Sep 2023 14:47:05 -0400 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD47911B for ; Mon, 25 Sep 2023 11:46:58 -0700 (PDT) Received: by mail-qt1-x834.google.com with SMTP id d75a77b69052e-41513d2cca7so70971cf.0 for ; Mon, 25 Sep 2023 11:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695667618; x=1696272418; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=cIe77vdqpeQpP4qLU2XoNxMwUlYUlcq3Ovdt56o2n9g=; b=IX3s4sxaz7OcP4jU5K9TFCJcYBbTaTK8DC5DVjpz7OFfhqVPQlFgRLfqEKUsd/fpqa K5biH5/2HQMAhlku0vFz3IjBUA7DXNFFNV1MoJw3ax9qbHLPThSPQ6Qe+4Ad71yD2QYe yj+tHqNMAp3BS6jdV0srKehUAJl0qNe9SAqBRCJ9qMhTdcudX39NuFlRFIYff9NSoIdS RD2YTeomljUlL3tTlcr93Q+NhmMeWQZj/ls/iH/UjLzuXXwUgr/cfUxIAlRVliZJJa/w u7TcMUJ6jF2NwsjW2Qri9gM9J0qAhh9OkyPvHVPT7TaG5HvADasNqUOyP+0lU3J+o4WX y4og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695667618; x=1696272418; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cIe77vdqpeQpP4qLU2XoNxMwUlYUlcq3Ovdt56o2n9g=; b=Pd6qVWG02hsyVIcNbcqd5xsScVieH8gLSiHvn1CyaCl2aYm4qREioaVaD5PUZpCaXs XiAM3nSFxRvnMZOjT24omsH2JrjBjpCOUPYAHqLjReE4odabZimtC0pF1I5z23AlJhBj nt+oCDrEEPaBBVXX/hh06ApugZp5I29EOEVqEgphaAJ2pASE1isj0EFaRT++ktk1dmsW /UW6p8MTf/4xBah58asQpBYihmtZatty/oavfWdMdnauOzHEVDbP1pjXNPKvyMMhr6hY HknVV9Ot+gBSZY57/TyFhDq6ejCeW6w80Gq/c0fn1I1O0/YRM9VjlYPr8zfEy4IrRgd5 bpfQ== X-Gm-Message-State: AOJu0Yy35eSx2/AmeVe+VXg0smQ3OeSiQSKR2Jop//vxE1y6X8zb1FqC 6SXljj/czx3iw5eHcvsPwh/9Khr/CSCPHA2onKMBEg== X-Received: by 2002:ac8:5a46:0:b0:410:88dc:21b with SMTP id o6-20020ac85a46000000b0041088dc021bmr52357qta.26.1695667617738; Mon, 25 Sep 2023 11:46:57 -0700 (PDT) MIME-Version: 1.0 References: <20230922044241.322832-1-cmllamas@google.com> <20230922175138.230331-1-cmllamas@google.com> In-Reply-To: From: Todd Kjos Date: Mon, 25 Sep 2023 11:46:46 -0700 Message-ID: Subject: Re: [PATCH v2] binder: fix memory leaks of spam and pending work To: Alice Ryhl Cc: Carlos Llamas , Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Suren Baghdasaryan , Li Li , Hang Lu , linux-kernel@vger.kernel.org, kernel-team@android.com, syzkaller-bugs@googlegroups.com, stable@vger.kernel.org, syzbot+7f10c1653e35933c0f1e@syzkaller.appspotmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 25 Sep 2023 11:47:14 -0700 (PDT) On Fri, Sep 22, 2023 at 11:51=E2=80=AFAM Alice Ryhl = wrote: > > On Fri, Sep 22, 2023 at 7:51=E2=80=AFPM Carlos Llamas wrote: > > > > A transaction complete work is allocated and queued for each > > transaction. Under certain conditions the work->type might be marked as > > BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT to notify userspace about > > potential spamming threads or as BINDER_WORK_TRANSACTION_PENDING when > > the target is currently frozen. > > > > However, these work types are not being handled in binder_release_work(= ) > > so they will leak during a cleanup. This was reported by syzkaller with > > the following kmemleak dump: > > > > BUG: memory leak > > unreferenced object 0xffff88810e2d6de0 (size 32): > > comm "syz-executor338", pid 5046, jiffies 4294968230 (age 13.590s) > > hex dump (first 32 bytes): > > e0 6d 2d 0e 81 88 ff ff e0 6d 2d 0e 81 88 ff ff .m-......m-..... > > 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > > backtrace: > > [] kmalloc_trace+0x25/0x90 mm/slab_common.c:1114 > > [] kmalloc include/linux/slab.h:599 [inline] > > [] kzalloc include/linux/slab.h:720 [inline] > > [] binder_transaction+0x573/0x4050 drivers/androi= d/binder.c:3152 > > [] binder_thread_write+0x6b5/0x1860 drivers/andro= id/binder.c:4010 > > [] binder_ioctl_write_read drivers/android/binder= .c:5066 [inline] > > [] binder_ioctl+0x1b2c/0x3cf0 drivers/android/bin= der.c:5352 > > [] vfs_ioctl fs/ioctl.c:51 [inline] > > [] __do_sys_ioctl fs/ioctl.c:871 [inline] > > [] __se_sys_ioctl fs/ioctl.c:857 [inline] > > [] __x64_sys_ioctl+0xf2/0x140 fs/ioctl.c:857 > > [] do_syscall_x64 arch/x86/entry/common.c:50 [inl= ine] > > [] do_syscall_64+0x38/0xb0 arch/x86/entry/common.= c:80 > > [] entry_SYSCALL_64_after_hwframe+0x63/0xcd > > > > Fix the leaks by kfreeing these work types in binder_release_work() and > > handle them as a BINDER_WORK_TRANSACTION_COMPLETE cleanup. > > > > Cc: stable@vger.kernel.org > > Fixes: 0567461a7a6e ("binder: return pending info for frozen async txns= ") > > Fixes: a7dc1e6f99df ("binder: tell userspace to dump current backtrace = when detected oneway spamming") > > Reported-by: syzbot+7f10c1653e35933c0f1e@syzkaller.appspotmail.com > > Closes: https://syzkaller.appspot.com/bug?extid=3D7f10c1653e35933c0f1e > > Suggested-by: Alice Ryhl > > Signed-off-by: Carlos Llamas > > Reviewed-by: Alice Ryhl Acked-by: Todd Kjos