Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp655022pxv; Wed, 14 Jul 2021 12:14:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4uAExJIvRzqG558reya1WYSWNhSmAzqZdjIEg+IVpyavjrSajmF4Hj8RM5fOQvgKpEm60 X-Received: by 2002:a50:aa97:: with SMTP id q23mr3944651edc.154.1626290045513; Wed, 14 Jul 2021 12:14:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626290045; cv=none; d=google.com; s=arc-20160816; b=QSY3xBDMd7iL90jOlyfEwx1krN7tvXCGq1OCyAYjMG5w3POEysPrYCdKQTlm/tCda9 3jlrg0GwG5yfaSEVOqfrFmqFXp7dKuu0gdCjhG/RTqMY/crCob5zhcHVb9wy9hfiFKEX 9Dolm1rWC93io0Pfb6PRl4JX1MGgPTzvRsRJvBccY0J4FwRct951RtUrvm5joZej1YH3 P7OMPaeLNrnyJSpvMpcIzlnwj9pVHnCDpDrcLnkwFEyPxTiDSSxS9CnomHrreHb8wXuc pu6aaHX4rm6l9pyQnw6C0nbcHaBOPj5wZ/lN4KMgxxwn99LNettXfawP5ThLQ9NoAj4h NRBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date; bh=BeXV+On5xHtteKD9gYAxHT/cVKEGJX/KMRsm+aNLlso=; b=s2sm1YIkwpw2e+3scNlS0wAzw1Z6qe0xW9eLm2N+qbTSJk8rRBk5xjHMEYAW9ptrQX MKmUnyZsUgcvykw+g5Nkm9jrhfzDfB2C3Fi0p7YEzRB465gQHkLxEjO8m7XSc2TtRuG6 ZyVRD4QMJFmriTTEnXlXyzZP/VYRfsqvvwgoabBnF6qk/pmHr2jU6hQp0D3R07gSRWml 4PoENMGfzRDx7Iu+xVEMzFQus7uLfe6QeOdlPmOqnFClM1Xo+7QuC3NdQXRLjQuMa+2O sEw0g4yIWYFTMX43IGlnoimpCIbKak6GRJWC03utHfC9evazCZEmggR2fDyjWPjOFcda 1f2Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb13si4224999edb.290.2021.07.14.12.13.42; Wed, 14 Jul 2021 12:14:05 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230269AbhGNTPZ (ORCPT + 99 others); Wed, 14 Jul 2021 15:15:25 -0400 Received: from namei.org ([65.99.196.166]:42532 "EHLO mail.namei.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229735AbhGNTPY (ORCPT ); Wed, 14 Jul 2021 15:15:24 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.namei.org (Postfix) with ESMTPS id 1F7414A2; Wed, 14 Jul 2021 19:05:50 +0000 (UTC) Date: Thu, 15 Jul 2021 05:05:50 +1000 (AEST) From: James Morris To: Austin Kim cc: serge@hallyn.com, keescook@chromium.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, austin.kim@lge.com, kernel-team@lge.com Subject: Re: [PATCH] LSM: add NULL check for kcalloc() In-Reply-To: <20210712234434.GA29205@raspberrypi> Message-ID: References: <20210712234434.GA29205@raspberrypi> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 13 Jul 2021, Austin Kim wrote: > From: Austin Kim > > kcalloc() may return NULL when memory allocation fails. > So it is necessary to add NULL check after the call to kcalloc() is made. > > Signed-off-by: Austin Kim > --- > security/security.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/security/security.c b/security/security.c > index 09533cbb7221..f885c9e9bc35 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -321,6 +321,8 @@ static void __init ordered_lsm_init(void) > > ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms), > GFP_KERNEL); > + if (ordered_lsms) > + return; Your logic is reversed here. Should this also be a kernel panic? > > if (chosen_lsm_order) { > if (chosen_major_lsm) { > -- > 2.20.1 > -- James Morris