Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2633701pxj; Mon, 14 Jun 2021 03:36:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoqfqkzuLHAb6Umdxkwxt0pM0IxWW9K3ZkzXQiLTconzIgTlZABTsg/2CQ40MESxcfCWZQ X-Received: by 2002:a17:906:b0c8:: with SMTP id bk8mr14811720ejb.412.1623666962312; Mon, 14 Jun 2021 03:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623666962; cv=none; d=google.com; s=arc-20160816; b=y8p5sV2Zl9EDkXL2r+TQmSYd2/qFrqRp/2czOOIS/bRLmWHaUXEj5oETM8VDYlZYCF mNYJM7smRr7SsNjj9cHNOlnfAQSrX3JLGqK7xYBQpyDT1ZVzKtGOnZ2ZeIW03fhCAF+S rUpOpzHUtzVGhWBvr2Py/s/4yLPgpyEoWc+ITGSnK3zhKOC1I6J3FLksxmEYO8YWf8Bb hU+Y3GPrwQ36MVfT3Ty6tQu7vxMCsSh6w6vBqTV2wJTjGitQlLEkgV871mjl17IPoJb6 7CPDtOr2NC1StkTBjD7bcdXH6+KHf/I27BZgz/TF8m0beaPuGKyw9eFV7xFwSEiwrlS+ P5Eg== 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=alD1dx6FaY2s3hl+GoHFvuCxRoXVIm43ss0GFWvAcnY=; b=M5t6OpqRvGUziikM7uNrqy5KwP1K7zK3O1CUVrMabL2lZIEjf0i/xBwGxeK1NoxFx7 OH7U8dGwbL3NCmGzUTXhfKvu8btB+DVY38FdaqSd4x1XLS6J5EgWpIEWI6fvx+f1B3gQ +7yTOdcw4t22AMCpIBvFfeJ2dl6w5PjDjrJwwU3XnMdw7gQS1k80NIde9IZyyTMiGDBV FLowegqEj+MszLcqGk13MOm0jVtUkZabPbbhqGyoGSKFLzlu1K/MSwOS9hVB+AoJNPKg nGiT2kUk7yZl+wmvsJQJ8/ok7Tu+3G4k6Kq9UkgXd02ZvYbKXvZaGsXT/inwGIhpjAP0 Saqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TFa5bP0G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e9si11668743ejm.426.2021.06.14.03.35.38; Mon, 14 Jun 2021 03:36:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TFa5bP0G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233165AbhFNKd5 (ORCPT + 99 others); Mon, 14 Jun 2021 06:33:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:39108 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233067AbhFNKcW (ORCPT ); Mon, 14 Jun 2021 06:32:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 98562611EE; Mon, 14 Jun 2021 10:30:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623666610; bh=YDAiIfHevNO5ORjS0kTUf9NlrNBWQqz2BWZOZuDAUng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TFa5bP0Gq9kQ1M/PGzO6aDHS1wJA//UX9+PXY9ocPkR49ff70k96D8CDu4yRYc+68 TW6rKH5fGtjscVC5R9qvbsfCH9TYkm/jjsFTZJgYxGBxd+t3/WO4QiKnVL617B14cc nQElTpxmV354zpf76Sl9XMhBci5oJt+eScKeKa94= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Kuznetsov , Andrey Krasichkov , Dmitry Yakunin , Tejun Heo Subject: [PATCH 4.4 21/34] cgroup1: dont allow \n in renaming Date: Mon, 14 Jun 2021 12:27:12 +0200 Message-Id: <20210614102642.265837815@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102641.582612289@linuxfoundation.org> References: <20210614102641.582612289@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Kuznetsov commit b7e24eb1caa5f8da20d405d262dba67943aedc42 upstream. cgroup_mkdir() have restriction on newline usage in names: $ mkdir $'/sys/fs/cgroup/cpu/test\ntest2' mkdir: cannot create directory '/sys/fs/cgroup/cpu/test\ntest2': Invalid argument But in cgroup1_rename() such check is missed. This allows us to make /proc//cgroup unparsable: $ mkdir /sys/fs/cgroup/cpu/test $ mv /sys/fs/cgroup/cpu/test $'/sys/fs/cgroup/cpu/test\ntest2' $ echo $$ > $'/sys/fs/cgroup/cpu/test\ntest2' $ cat /proc/self/cgroup 11:pids:/ 10:freezer:/ 9:hugetlb:/ 8:cpuset:/ 7:blkio:/user.slice 6:memory:/user.slice 5:net_cls,net_prio:/ 4:perf_event:/ 3:devices:/user.slice 2:cpu,cpuacct:/test test2 1:name=systemd:/ 0::/ Signed-off-by: Alexander Kuznetsov Reported-by: Andrey Krasichkov Acked-by: Dmitry Yakunin Cc: stable@vger.kernel.org Signed-off-by: Tejun Heo Signed-off-by: Greg Kroah-Hartman --- kernel/cgroup.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -3310,6 +3310,10 @@ static int cgroup_rename(struct kernfs_n struct cgroup *cgrp = kn->priv; int ret; + /* do not accept '\n' to prevent making /proc//cgroup unparsable */ + if (strchr(new_name_str, '\n')) + return -EINVAL; + if (kernfs_type(kn) != KERNFS_DIR) return -ENOTDIR; if (kn->parent != new_parent)