Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4859897imm; Mon, 11 Jun 2018 21:20:19 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIo0GTNIhkcrLG/00JYdEcAeQyYhcanG0IDj2J6fFE9iZY1APgeTxE5OEYG4ln1D+g4wWiM X-Received: by 2002:a65:640d:: with SMTP id a13-v6mr1792417pgv.154.1528777219761; Mon, 11 Jun 2018 21:20:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528777219; cv=none; d=google.com; s=arc-20160816; b=zs0hHHz/oDoAMXxWt7FSjkhWEakDo55dGEXxKNCSRSxW/lni638YzXCoILzGvfB8Ug Hcz+VZNfJTUqdL6vkfQNogdjT6j8fC+mWoOgn0QVqfQVf098SxrhJQRrMAtLAAJKGZGM eGcKgIjEK0zA1Bp98VRC7jBT4oN0lXt/mFj9W7l0xxIxBdieVnjB/9t4awdB1DCAPSdJ PFd6v2onzot2Arqh3NSmM0BJn33x8lsDqeR0ksi8ZocweZQIL6+BqhghYH52lOiZk0ZP sYt/SCMNJZCEc77D2Ymnl2H+84m6oArCoJK9eS8QCG1sZOmQPAOuQzy2oYAsgUkUhU5p aQjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:message-id:date:subject:cc:from :dkim-signature:arc-authentication-results; bh=F+GFV2KjdqB0bR40IfmTpZtntOLDxZbv1eGUZATGvUQ=; b=TM7gTZ79l72I+ERtQLtGXI27k4Fb2eORCrFhQd52BPivBhWrf6IV67ouRDPk1EJ3PM DKG+mOmxNNM5VQjttfoLS3/elWN9DpshYG24XF7RjNWB2hlaQJWdqT78syDXJ5n+Xy00 0M/PHb1ur0Q9K4cH3/psIEaAunRfTeP3O8S1o4VAfbLNnkOUPpg07EBtchDoDfTL+wql BrGTtGpJL5VkvNFphYITwdGCVB1/ZeDpnOhHNuxIlvMxbBbmfjK3+G3psREeB/ol1CKj +Q6X1CYwuhE+bp4r0vn3+ilsF3PKtkoC2OM76S7gI2CTYYxFRK3GH9EBpG1ytYtLAYBj IjiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=tzNB/PWK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o21-v6si29847177pgn.262.2018.06.11.21.20.05; Mon, 11 Jun 2018 21:20:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=tzNB/PWK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752816AbeFLETm (ORCPT + 99 others); Tue, 12 Jun 2018 00:19:42 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:40349 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750811AbeFLETk (ORCPT ); Tue, 12 Jun 2018 00:19:40 -0400 Received: by mail-pl0-f68.google.com with SMTP id t12-v6so13577580plo.7; Mon, 11 Jun 2018 21:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=F+GFV2KjdqB0bR40IfmTpZtntOLDxZbv1eGUZATGvUQ=; b=tzNB/PWK+sqmOwMAXvDTIH0IZyEcQV6JZazPi+1yATccYhqAyOdFOHtwCxm5q4ALZy k23Pp/3tMQZ5nMsbo6gi9d/xUkPiFBzihOAEYqNFGDrYr4EQ8gFHWdLJSJzTB+a5Ug6x gYfPKxOMvd+OTGdjnTLEvBeZvd7Pqx7QRco4B2Bp9aghZ7LBsRhNEsboSyhBHC0D7qj2 TtHdDrfQKLU6mE0svvl2VmElHipep8k2k9wUgrm1jq+cTH1c2q1Oo81B1l8/ThGn3Ajb 9TBiHq5XpovSNpThK9uCxGNHPdadMfQ8pwrbqC5IwLtB5n8ECA7tOJwaSNEFkpQpkDFH GYgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=F+GFV2KjdqB0bR40IfmTpZtntOLDxZbv1eGUZATGvUQ=; b=Djqo8LFZysIxkUB/ELzSr3NAwyr5IW4G0Z7ubr51GPfGxPQQAyTc+qI4z+AZ6jI/PQ O1lTmgqyWNq2zJimJMRDjd/4atzHz7yAtxxlOshp7YKzMQtn5bjCUUImIxe+gNj0IQBi b8/jlb8wiIPaUjg6sjC8UgRoUc7/Lek+AwMDF9VtCz0aNVFf6dmSOS3BCAD1GMxpK0qK 6fsUG8knRPCTm9mIn/3vDmqnFJjIhpa9/i0Wh0HkZsQZxrC693mHjpqsYtF2sC48mAeK uI67FKnF472qoLB8lbHku9lrj+w8Kd0D9v8eklvSieezI9PZbKOkZyt3re+jxb+p4m2w vwQQ== X-Gm-Message-State: APt69E3PldcNq46HP//s5ov8BEHlvFGcglo1EeCjoSPBfBCkfxF5YW82 FPPJHxVgtbspXLvIExOXKBk= X-Received: by 2002:a17:902:6b0c:: with SMTP id o12-v6mr2150507plk.159.1528777180237; Mon, 11 Jun 2018 21:19:40 -0700 (PDT) Received: from localhost ([103.88.46.82]) by smtp.gmail.com with ESMTPSA id o77-v6sm84856375pfj.0.2018.06.11.21.19.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jun 2018 21:19:39 -0700 (PDT) From: Zhouyang Jia Cc: Zhouyang Jia , Jan Kara , Amir Goldstein , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] fanotify: add error handling for kmem_cache_create Date: Tue, 12 Jun 2018 12:19:34 +0800 Message-Id: <1528777174-40045-1-git-send-email-jiazhouyang09@gmail.com> X-Mailer: git-send-email 2.7.4 To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When kmem_cache_create fails, the lack of error-handling code may cause unexpected results. This patch adds error-handling code after calling kmem_cache_create. Signed-off-by: Zhouyang Jia --- fs/notify/fanotify/fanotify_user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index ec4d8c5..e3fa861 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -959,9 +959,14 @@ static int __init fanotify_user_setup(void) { fanotify_mark_cache = KMEM_CACHE(fsnotify_mark, SLAB_PANIC); fanotify_event_cachep = KMEM_CACHE(fanotify_event_info, SLAB_PANIC); + if (!fanotify_mark_cache || !fanotify_event_cachep) + return -ENOMEM; + if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS)) { fanotify_perm_event_cachep = KMEM_CACHE(fanotify_perm_event_info, SLAB_PANIC); + if (!fanotify_perm_event_cachep) + return -ENOMEM; } return 0; -- 2.7.4