From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD6B7C3A5A7 for ; Thu, 8 Dec 2022 03:44:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47E4F8E0003; Wed, 7 Dec 2022 22:44:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42F0F8E0001; Wed, 7 Dec 2022 22:44:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34F478E0003; Wed, 7 Dec 2022 22:44:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 25EF38E0001 for ; Wed, 7 Dec 2022 22:44:04 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EA7B680458 for ; Thu, 8 Dec 2022 03:44:03 +0000 (UTC) X-FDA: 80217745566.20.72DBCDC Received: from out-120.mta0.migadu.com (out-120.mta0.migadu.com [91.218.175.120]) by imf07.hostedemail.com (Postfix) with ESMTP id 011CF4000D for ; Thu, 8 Dec 2022 03:44:01 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=vpawLfoY; spf=pass (imf07.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.218.175.120 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670471042; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PHzE9f0IRUY0L+BGXdPC0ZZnOe1x/EoBD8nxdnVzP/M=; b=1ro7vqS/gwuXfuFcwh+8DGSIcM0fas6aQ1QjDo9Lfyy3r0dlaIao7vd5dyc9JXqSclb3uy WSL9XnZh4hFFAdMLmagIe1BJyRio9JmFc1ZGuv6hUamn8271lSG3BK2GiLfv2U3W/hpEIB CMrEOU8maoq/2SF/K77DFJXrpjWho3o= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=vpawLfoY; spf=pass (imf07.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.218.175.120 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670471042; a=rsa-sha256; cv=none; b=k8FjusB8lCn2lvkjfg/s3x1sDrEI89J9uU0cbX18n6AUWBQbWkQGzzJq1zi7Ugyt52Lffh sbzJURDLtVsSG0PPfeHt7JZIGY+jcI8lFR/VZrkhXtDkXPvHqtY77O8u+eFVtlGHTmEyXl kxMvfr43dP8g617mbqLCbeJyop7yOa4= Date: Wed, 7 Dec 2022 19:43:54 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1670471039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PHzE9f0IRUY0L+BGXdPC0ZZnOe1x/EoBD8nxdnVzP/M=; b=vpawLfoYzk62tmgVNEmN5i8T2NCxM8fyGPGuFK7gqTTc/b4UNKhdNtVkDsglOiD7bxhqUE 6//7BfzL6tZuikORiTWga4fKG87s+XhgCLh0x6R+ICFivUvBWSSNyjRNTBg5DqVbbx6L8J YvqLamYDqJLmT4kHILPITmgw/sC4M8E= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Tejun Heo Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jann Horn , Linus Torvalds , Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , cgroups@vger.kernel.org Subject: Re: [PATCH for-6.1-fixes] memcg: Fix possible use-after-free in memcg_write_event_control() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 011CF4000D X-Stat-Signature: 4xycfhcpz1kn657yu5cqq9fc5mitow6h X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1670471041-5410 X-HE-Meta: U2FsdGVkX1/Sn0o8CueoWJecWn2fHE/HTe3mFWVkYKF8ry6M/DVeUQmd4U0xNsnVWIoPSp4UGCyjy+x/xdfuE/QHiaoGh3TjZMBsIuHzRhH+lRsaUZy09C6VGH56YlbJsiu+2mSYq64Si+NVpACEMMuWLM7USryyujUzqF3sx/Yg/UT7nnEeu9PqaVav2hMe83pAnxavtbryi+LOQ0nVfA/rjECcfqPx5H8beH+Ff+c8QsEOfeC7y7ZPQQ/GvgAm6n3TFr3/edFmoqrToTYevnDT3rM+/O2L3wYCI+D1sk+8Hxx2UTAEFkrayPTMjVWjBATHEsHMmgU/SkXYPhCtsXti//2dccBsPsrjvJVCkL8tjkZLzsxCfbhBtxqaAQ4LSIeAsPIQFnj0bCOc547qOcuieFKyyG8IilU6mvGTs4D7k5s70Ht69DI6rYja22jDRls8cwIzA/MkPxAYtaosnbxwpsxFJhjvuu6gLONa4bqzp9luZd27dvK0TleZ4cxkowJXqaJUvRNb+rwUghvx5TlpNLEAbtqIR4yJYkLwPGCuY/nfzknvaVuNeWj18tGJqlQH+/BUbjTgmMzpnKT5kRSnVt6aIWaDdFCUkgA3XK/Vb2zvw3/tw/9mAv/IzTcO5TpKMKEFdgmRridwmZvvdKKIXFI8tQN910Ku8UlEubKErj0/+WKTE49leH9i4CJ5qVtYESnao+JSQJ2qY43b6lMYH6wASKZx9pR5vS5udt1iBAS9nR4f7e7BskkkHdD8uzXguL65JkszZltLcsavnU+zUVuf1qq0fnOCSBVvp8qn/WvB0dttfqTPrDx7HjQTABryPiPq7+NB6/2C9y/boLAqKiiZHEgclgPofL77Bgg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Dec 07, 2022 at 04:53:15PM -1000, Tejun Heo wrote: > memcg_write_event_control() accesses the dentry->d_name of the specified > control fd to route the write call. As a cgroup interface file can't be > renamed, it's safe to access d_name as long as the specified file is a > regular cgroup file. Also, as these cgroup interface files can't be removed > before the directory, it's safe to access the parent too. > > Prior to 347c4a874710 ("memcg: remove cgroup_event->cft"), there was a call > to __file_cft() which verified that the specified file is a regular cgroupfs > file before further accesses. The cftype pointer returned from __file_cft() > was no longer necessary and the commit inadvertently dropped the file type > check with it allowing any file to slip through. With the invarients broken, > the d_name and parent accesses can now race against renames and removals of > arbitrary files and cause use-after-free's. > > Fix the bug by resurrecting the file type check in __file_cft(). Now that > cgroupfs is implemented through kernfs, checking the file operations needs > to go through a layer of indirection. Instead, let's check the superblock > and dentry type. > > Signed-off-by: Tejun Heo > Fixes: 347c4a874710 ("memcg: remove cgroup_event->cft") > Cc: stable@vger.kernel.org # v3.14+ > Reported-by: Jann Horn > Cc: Linus Torvalds Acked-by: Roman Gushchin Thanks!