Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp184828iog; Sun, 12 Jun 2022 23:36:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUBHZBqPuUvux8lX9jmzLUpCQHSugEpcBA5oKnnbGmxFwkm7Er7ulx4RvRrzWZPMDKV3WZ X-Received: by 2002:a17:90b:1194:b0:1e2:d261:202b with SMTP id gk20-20020a17090b119400b001e2d261202bmr14134027pjb.25.1655102174233; Sun, 12 Jun 2022 23:36:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655102174; cv=none; d=google.com; s=arc-20160816; b=o1e9vnetxMveavYlvRZuAguIk0M7RKbyMksHddID5AI50OarowQQXabeWwhgRPuXez hb+Zm8JArNfTkuwZUONwA6rqhSa+c/SLEmvmClBEVyAYqj9XUidHM/n4p4uczDgq9qWO Y36gkPEGEfrDA7IoYh29ga/yGMlMYyGxIWFUNIXlZaM5AltrHXTIKePmzAs0U/zPBNva 9sBkvumVr49C+gRKA27XrZ/0fU4I7INUWYkBft8uqQgCzVLAFjhWimzYvGmrckNgNgK3 51+VSqFIzVgN0HMeREJ65WXgK0431GbOr/RBXM0P9F3jIZ3Cn86GSrmtaDQVuIDnreJL hNzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=gV/MDGHub19a1mp3jXrl6UjrQIow2wXoeBzWCS2dwyg=; b=ZZdVNFBckk1qhy5wETqQUpH8p3gGZlSZ/Hegvq+2QJ7Pkb4mS/BcX66XLg1Ep/cb2O CJ3vHolVp+Uz5ObemaqQaEgbtTwLqk4S1FfF34d8LyHd73X8ZNtEEAQqtX2A/75HzkPv k3nUWCvussWh/M+3sFivTAzrUIFpkE2YrI3OQ+xU44Z6ZHodU+6AqaOcdtnw9vWGjMo7 IHep1iVKFvfUOZdUfPjuMQL2JWEMw5K09Z33fsHMsZyEibf0JNRygb5juAcbSQviTqhb CZtpbgQauZpvZ63LK3CYhjXgzQfs8UuggTKHJ5w78ho3WxeRc2lsuofsBIDHbL2neKDl AJ1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b23-20020a056a0002d700b005183163dfa7si7653484pft.267.2022.06.12.23.36.01; Sun, 12 Jun 2022 23:36:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231241AbiFMGXE (ORCPT + 99 others); Mon, 13 Jun 2022 02:23:04 -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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.25.1