Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp758889pxb; Tue, 5 Apr 2022 22:04:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJDcuLHTmTTdwL9pqTLZYAQsan1zOpARDjIeMl9JiFjtMHXvi+oFjrVHr82ZuwWko4LZw/ X-Received: by 2002:a17:90b:4ac1:b0:1c6:adfe:322a with SMTP id mh1-20020a17090b4ac100b001c6adfe322amr7988099pjb.189.1649221457471; Tue, 05 Apr 2022 22:04:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649221457; cv=none; d=google.com; s=arc-20160816; b=oM46SAGpSw7el/gyJXGaq+bN94OX7BVjDGbOgyaEZYU2fKzDw1qdwN285WRoekwZ20 4swsIkYYeNtpj7WKVY3GBrbXqF4qSjOSdQepcBVSfS5NfMr+WBSAM3CgsxJtOPloai48 DV5iaK0xBKhXRdmzhzwWuSPfUnZQtDi7mphJ/2sxUNcq2WFkoug29Wv56ApvsqqNtuGL KZDiT8ePgUfMOe9JUtF5sp8cYb8rbUJdatMfZf+53hzW77TqinZNFHCUlklh0ofCkoRK Bn29e6rFttBfjdVZnUhgBh9Ha9H6moJ2LA2ohq3DmfE9+Nfc3CccKv6i1Y2Gc3kRgOPH 0mSg== 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=ANWwoUrvwN9mvhHGUfojXstcJBVnYdmVC4hH3kuTzP8=; b=LdwI06tzMy2HAFViQqKV0Kyc90KWmd35wb39X2vCJkjvSmay8YLkwqBpGe3gQqtf/S Szpmss+sL4SsB3FAFBtS+vlE+Ea9aTs7auHpyDjSOsyuFAaalOt5u03Mdbo9Mq8m9B9X THxgRB5VkZJl4ZQXUlzv7WoDUC6p12nOGIs5tUKlZE81pwJ63nU3zuqwCQ08Vr3BDuYT RtIVuPoOfS+iY9ohZ/QRMZcKhP2njKfOIvFfQ5p1OKMUMfvPPJsSMBi0Z5mZxDnqLY8I wCqF2qtrQ3O2WBSrpLs4oSgB2jCOfYR1LC4oJHbDOCneN6GN2xFW278wlKRZvsOhpcPV zc1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=obkCqheV; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id p10-20020a170902f08a00b001501189ca21si4366486pla.1.2022.04.05.22.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 22:04:17 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=obkCqheV; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 F3A4146B83D; Tue, 5 Apr 2022 20:23:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241351AbiDEIdS (ORCPT + 99 others); Tue, 5 Apr 2022 04:33:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233223AbiDEH47 (ORCPT ); Tue, 5 Apr 2022 03:56:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A064427DE; Tue, 5 Apr 2022 00:50:51 -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 A047961740; Tue, 5 Apr 2022 07:50:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF58EC340EE; Tue, 5 Apr 2022 07:50:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649145050; bh=0m1s9fY8emgpod7a0c86QGW3B5W4ZS13ZfoY2qqIbTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=obkCqheVI4W2j3Crud5Xn6Ni3j9YkHIJIAfkBU6dfPCmnoLGeAKl+gMRaVkIaJlO7 5rXZYjKprR79YI1dh4EFSc9DBbIKeUP0yVjn3L3WQcV4xxtmY382clLz2re87AfRJc DWXdbEYRYN/G3jh5yAgT+CVPOdzTOoyGOThguncU= 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.17 0267/1126] watch_queue: Actually free the watch Date: Tue, 5 Apr 2022 09:16:54 +0200 Message-Id: <20220405070415.447858221@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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 5848d4795816..3990e4df3d7b 100644 --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -395,6 +395,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