From patchwork Mon Jun 13 06:22:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiong X-Patchwork-Id: 12879048 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19838C433EF for ; Mon, 13 Jun 2022 06:23:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230215AbiFMGXB (ORCPT ); Mon, 13 Jun 2022 02:23:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233335AbiFMGW7 (ORCPT ); Mon, 13 Jun 2022 02:22:59 -0400 Received: from mail.nfschina.com (unknown [IPv6:2400:dd01:100f:2:72e2:84ff:fe10:5f45]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 445106411; Sun, 12 Jun 2022 23:22:58 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 708251E80D53; Mon, 13 Jun 2022 14:21:47 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GDzKuEfJdHjk; Mon, 13 Jun 2022 14:21:44 +0800 (CST) Received: from localhost.localdomain (unknown [180.167.10.98]) (Authenticated sender: liqiong@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 4C4111E80D05; Mon, 13 Jun 2022 14:21:44 +0800 (CST) From: Li Qiong To: Casey Schaufler , James Morris , "Serge E . Hallyn" Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, yuzhe@nfschina.com, renyu@nfschina.com, Li Qiong Subject: [PATCH] smackfs: check for allocation failure of kmalloc() Date: Mon, 13 Jun 2022 14:22:02 +0800 Message-Id: <20220613062202.29194-1-liqiong@nfschina.com> X-Mailer: git-send-email 2.11.0 Precedence: bulk List-ID: As the possible failure of the kmalloc(), it should be better to check it and print a warning message. Signed-off-by: Li Qiong --- security/smack/smackfs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c index 4b58526450d4..0d11ba3cb4cd 100644 --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c @@ -695,6 +695,11 @@ static void smk_cipso_doi(void) __func__, __LINE__, rc); doip = kmalloc(sizeof(struct cipso_v4_doi), GFP_KERNEL | __GFP_NOFAIL); + if (unlikely(!doip)) { + printk(KERN_WARNING "%s:%d failed to allocate a memory for doip\n", + __func__, __LINE__); + return; + } doip->map.std = NULL; doip->doi = smk_cipso_doi_value; doip->type = CIPSO_V4_MAP_PASS;