From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752858AbcFURGf (ORCPT ); Tue, 21 Jun 2016 13:06:35 -0400 Received: from mail-yw0-f193.google.com ([209.85.161.193]:36446 "EHLO mail-yw0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752261AbcFURGc (ORCPT ); Tue, 21 Jun 2016 13:06:32 -0400 Date: Tue, 21 Jun 2016 13:06:24 -0400 From: Tejun Heo To: Johannes Weiner , Li Zefan Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH cgroup/for-4.8] cgroup: allow NULL return from ss->css_alloc() Message-ID: <20160621170624.GK3262@mtj.duckdns.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.6.1 (2016-04-27) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org cgroup core expected css_alloc to return an ERR_PTR value on failure and caused NULL deref if it returned NULL. It's an easy mistake to make from an alloc function and there's no ambiguity in what's being indicated. Update css_create() so that it interprets NULL return from css_alloc as -ENOMEM. Signed-off-by: Tejun Heo --- Hello, I'm applying this patch to cgroup/for-4.8. Thanks. kernel/cgroup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 86cb5c6..8e5470d 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -5139,6 +5139,8 @@ static struct cgroup_subsys_state *css_create(struct cgroup *cgrp, lockdep_assert_held(&cgroup_mutex); css = ss->css_alloc(parent_css); + if (!css) + css = ERR_PTR(-ENOMEM); if (IS_ERR(css)) return css;