Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp627398pxb; Tue, 5 Apr 2022 16:27:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaRYr8OBuWJbsfCcgYoPkMqPTqn5PQV9bs7etD0M6SNEp1h2h5VrwpZ07a7c4RsM2JaTxN X-Received: by 2002:a05:6a00:16cd:b0:4e1:366:7ee8 with SMTP id l13-20020a056a0016cd00b004e103667ee8mr5892822pfc.9.1649201273732; Tue, 05 Apr 2022 16:27:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649201273; cv=none; d=google.com; s=arc-20160816; b=ypMxvCN4F75eW5x+EK2HGMR/cWw/HZ2gXTcpZad5WQ1Ltn3psTaDFkTlVkKK8ft5Vk C3yT6m1p5bcf5JAS9in9KgpAquRJdXoae50xylcMM7TMc9ldjo7dHM8Ya879mE11eNo2 NPSXiyejb0t4XIRbwMNI/ShOuZA2Bvw5eJcKepLrXnJ1518z6uofBmNfHEmNsVMMVBcJ 8NsXL6xPjyAUkIs9NzoOOVUySWsz3HZYduIEpaQvRMvkNSA1XzveM39ozbQLVHu/dD01 XITuKv8UuEiIha2LOomzt0fnaE916jSWZdZWxw9ph/WLuF3UjSnyiEFsEhHWX5FJV84D zMTQ== 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=beYnKF3S7tWl5s4/iQCXFzfymCdATEU0340Pu5KWYuI=; b=bTo6nD7XgrcGdUieEpRcyp0+LOWFGWJKs5CYFAbG5yhzihmoVyUupVOYIvhslPsMeW 5ezy7wkKgDaSRnhzCQkGgzKIvX1hoBIJ0AHbftWqE1Y9eGRY0cQdprIXnT/wo+rtOpjZ BVmDtKt//WsiVHRCas+UNmJfHGDLM7bfv1IHlbURC3N0hBMFKKH6a/VWNXWkoUdt4B5Y fkdO9eqiJUs8fcjhgvOdNo/akoLZtUO66ulOkjRs7/u8HWT584/BrZu0HM1MJAILkZys uaXqMnJRouUWjOXSDzj54cLkclrmjSSJVA4CpO/e4cMAa+/iF5oLYb3QEFeZmvybVj1+ eQfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ntu8wnMe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s18-20020a63ff52000000b0038212d5c721si3701714pgk.542.2022.04.05.16.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:27:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ntu8wnMe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E6154F3FA8; Tue, 5 Apr 2022 16:11:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378748AbiDELid (ORCPT + 99 others); Tue, 5 Apr 2022 07:38:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244726AbiDEIwf (ORCPT ); Tue, 5 Apr 2022 04:52:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 585E11AF23; Tue, 5 Apr 2022 01:42:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E717961003; Tue, 5 Apr 2022 08:42:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 037C5C385A0; Tue, 5 Apr 2022 08:42:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649148171; bh=M67CU+T4xOG6XH0wlo3yuSohmbR82pONZTeDDfPjaTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ntu8wnMeo69V0184+m/l7gXWA2GbxPOZ6aUi/j7DCVZvKk6GlH2qTZkXv2FgKvQ/3 pDDq7RJp4yizKIVPJbIGJRcErrFUhVhjuj1ebiK2Un63otbzky3ckNN1ikah8JvkaP KVIA8XpGcaUFixTm7AcxAkWYgNV5w+x/BuxhCHjs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Howells , Sasha Levin , syzbot+6e2de48f06cdb2884bfc@syzkaller.appspotmail.com Subject: [PATCH 5.16 0258/1017] watch_queue: Actually free the watch Date: Tue, 5 Apr 2022 09:19:31 +0200 Message-Id: <20220405070401.921857691@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: David Howells [ Upstream commit 3d8dcf278b1ee1eff1e90be848fa2237db4c07a7 ] free_watch() does everything barring actually freeing the watch object. Fix this by adding the missing kfree. kmemleak produces a report something like the following. Note that as an address can be seen in the first word, the watch would appear to have gone through call_rcu(). BUG: memory leak unreferenced object 0xffff88810ce4a200 (size 96): comm "syz-executor352", pid 3605, jiffies 4294947473 (age 13.720s) hex dump (first 32 bytes): e0 82 48 0d 81 88 ff ff 00 00 00 00 00 00 00 00 ..H............. 80 a2 e4 0c 81 88 ff ff 00 00 00 00 00 00 00 00 ................ backtrace: [] kmalloc include/linux/slab.h:581 [inline] [] kzalloc include/linux/slab.h:714 [inline] [] keyctl_watch_key+0xec/0x2e0 security/keys/keyctl.c:1800 [] __do_sys_keyctl+0x3c4/0x490 security/keys/keyctl.c:2016 [] do_syscall_x64 arch/x86/entry/common.c:50 [inline] [] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 [] entry_SYSCALL_64_after_hwframe+0x44/0xae Fixes: c73be61cede5 ("pipe: Add general notification queue support") Reported-and-tested-by: syzbot+6e2de48f06cdb2884bfc@syzkaller.appspotmail.com Signed-off-by: David Howells Signed-off-by: Sasha Levin --- kernel/watch_queue.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c index 12348b41d7ad..38a135d68c05 100644 --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -398,6 +398,7 @@ static void free_watch(struct rcu_head *rcu) put_watch_queue(rcu_access_pointer(watch->queue)); atomic_dec(&watch->cred->user->nr_watches); put_cred(watch->cred); + kfree(watch); } static void __put_watch(struct kref *kref) -- 2.34.1