Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp99399lqh; Wed, 27 Mar 2024 16:26:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWmG8b1b++1HteZSXxfztPZjhEWY8qotnn+zE2fui3DyNAbzWWEgOsCkl40txyCLoXF0vT+Us/9awauh12NX9rhEyuMDuHqgZI+lyB5rQ== X-Google-Smtp-Source: AGHT+IEDCOvANDIKa9BpTAfFOomHELKYCaiCR01JY6jGo14zABsrVkHp+9z2/nwGF2Xw7SfKZVpp X-Received: by 2002:a05:622a:1905:b0:431:80fc:b691 with SMTP id w5-20020a05622a190500b0043180fcb691mr1437240qtc.19.1711582002967; Wed, 27 Mar 2024 16:26:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711582002; cv=pass; d=google.com; s=arc-20160816; b=Ch27AHsjPKQ69sAtZl7YnjNlbA43ZWs2o0y3R2iUP0gwSVd9ezYIToMVGgCUkEY69T kK+rg3faBZPeqNb5V/vBLI24dDz02r+Sw7AcAk1DRKJY1foaBJ+mL2j8wsypvLq33QJX X1p6PQKt6ocS2Ag/GZSt0OtkZojplEHrifVPuJhp+dF+awK3PVUm4OUYhhLTNWqUBh8N vkJ1I5mQ9KCsYfC2TvbIUqc7AqJ/uk4Brz4RP4qpPMjbcgX1I2E8KXmGcRVqMhr5ZhLa XIwzou/94WKkMOfMBC7YZ/dENJlGbhxuGU6vVf+8tlvmWYgbzsEQWXOrqQ5NxNKqESgm jPrg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=+T12fKZNKy57IbrXvGN5IsMMR+Ds6fYdnTifIne9es8=; fh=f0PK1zA+7vcsSkxSGnpZpnQ3ZG28ADlfpM9yEE6w/3I=; b=xuCd3e7VM/kPDIMGJ3ViRU1b04K58VhLM/dXgPVvYtSkj9cSmZZVz/NWhYq0PSwCmV reMB19a1NRDtwOBpLcgxB34g59F2G2e5p/YBJwli06jHWdQPzQRO33nuO8tYgB8sjyh9 rA9Nv6GxV4aDStWmzmxLHCyJOWJPD4AUquPCgvdfhfNL0nwae50c5AQAN1rBXVWGWesp TewIoFVGWviwrIEpbO62N8MpjcOokFHMGIlYeO23jv7xACgN7+HdV2xXKcWo2ZdK95s7 YiabElWf+kK7WTsg81qQOI6EXcvNKpv6eSStfTkzObLnKvUYtbYyWSa1oLgP7cNNPwwa EQQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kVlcRakS; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-122180-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122180-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m7-20020a05622a054700b004312a2553b8si181546qtx.802.2024.03.27.16.26.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 16:26:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122180-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kVlcRakS; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-122180-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122180-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 13DD31C301D4 for ; Wed, 27 Mar 2024 23:26:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C95D31552FC; Wed, 27 Mar 2024 23:26:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kVlcRakS" Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 727CB1534E8; Wed, 27 Mar 2024 23:26:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581964; cv=none; b=KS+NWwO4JeuZ84WeAsixMfe2T9t3SjLEhS8a6sVIKFo+Rd0NTR5n5FwqKDd5ze4FTNlI+I/HtBHohrZn8gmWLdSbKrR8nu8jUZfbK/eGeUSGOjJAKH3BNJWpQguDufx22WKmoujByUBNGiBNY5XBTK1Q/XCuW2ObwKoR08zKwHs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711581964; c=relaxed/simple; bh=PlZwKOxY2H1fF/5+DcCGrpjUWbv+K7OzN+L2CRgdJgw=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=fc+ebiieNVgKqI7sROZN83i+RiwIs9cE0kZM67WgWoTlbkUk4wDjYLh4/zbkL+ng5MGKSXPm898uYQ3AET5slEzB2RkG44pXtrVh+2TGETi8bhD4JZSR3DwmUNxeoKHVYuEpJZWE/dlPBKNZRiIG7/sybupil54GKekqcwMLwEg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kVlcRakS; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1e0f0398553so3780995ad.3; Wed, 27 Mar 2024 16:26:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711581963; x=1712186763; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=+T12fKZNKy57IbrXvGN5IsMMR+Ds6fYdnTifIne9es8=; b=kVlcRakSMM+FSCq9eq7g3GYBC/1n765WhgdZutycxbHEhoelOC/JOQU9vVaiH1oapL NhqYBrBZNY5/8y+JShfZTGEg+FpUjL2VLl7fhvSHuFp+qCs3gqhS1hgcz6/wvCwfZFyL 3orAaUcIJlfIyPO39meW9kjaMT0rFbAjIHmW3xF7scsrWKhbrVYVani5AaifvEg6tIv5 qx6CiFWQe5B05WW1Dp7qDGAJyE0maoZjkzuXLefABFNcjL5VOrYtKGwVc9p31tUcJ3WO fUkQ5wvxoX0F8nl2ivXxDSyrPgVS5r47rpRBNnXqs8Rw6eRfZxVEneDay5MzvxzXt86G +STQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711581963; x=1712186763; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+T12fKZNKy57IbrXvGN5IsMMR+Ds6fYdnTifIne9es8=; b=MF9InQnEWGFatBd/a4V4uYW3ClwDYu1Mnsz4VQtIxO5FuROepTI2LMj831ElIrXFBo SCnGZ/8UjnXdS4/Gq4PCxFJ4l6yhzh1K0EwxEjAnq+oCoSBc8z0Y/25MMUYhgDNvGGWW XqH3KzrsRFPZwnt78GLqlFLcCQJAWYOuh5pGF1Jam6/cCsTVrE4a75uDiHR4fwjPlYpl JYTx92X8r8spQrUdRheG0XLanLFXJT+3dABjN8Oh5Bpf4IaDXgN7yB0hRBVaiJAwGNFw TiE9JFpUbkv4WGOzX0rwibTSmx4Tlt+QwrlDoCIBdaV8pkBlFsvLVi/8gUGCc+KMyb+O FjdQ== X-Forwarded-Encrypted: i=1; AJvYcCU1GjKX+fCX9GfwPJEkZHzHoxYl4NmF+Grq2pE3nqR3jGtijfLdsYSczkZtjswzbvY6bcOwhVOBwbG7yF215Ps09JdIkvAeRPuYQNe+pCHyaiFGoafSbXRWyEb2BO+fjdp8vSkb5IhSzFkTfCphSIZPg6M4 X-Gm-Message-State: AOJu0YyvXxAIxGRoA+Qa8jETRjlA446h8HaBv9I9B1NW6qso//iZoab9 No+B2aoOnH3WRZb7GGxGOaZl9f8btC5782Lex5uz9KP+TQi4xO/7 X-Received: by 2002:a17:902:ecd1:b0:1e0:b287:c1d8 with SMTP id a17-20020a170902ecd100b001e0b287c1d8mr1432604plh.5.1711581962667; Wed, 27 Mar 2024 16:26:02 -0700 (PDT) Received: from ayush-HP-Pavilion-Gaming-Laptop-15-ec0xxx ([103.6.158.68]) by smtp.gmail.com with ESMTPSA id f8-20020a17090274c800b001e1020d4070sm72877plt.307.2024.03.27.16.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 16:26:02 -0700 (PDT) Date: Thu, 28 Mar 2024 04:55:57 +0530 From: Ayush Tiwari To: alison.schofield@intel.com, paul@paul-moore.com, mic@digikod.net, fabio.maria.de.francesco@linux.intel.com, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org Cc: outreachy@lists.linux.dev, linux-security-module@vger.kernel.org Subject: [PATCH] LANDLOCK: use kmem_cache for landlock_object Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Use kmem_cache replace kzalloc() calls with kmem_cache_zalloc() for struct landlock_object and update the related dependencies. Signed-off-by: Ayush Tiwari --- security/landlock/fs.c | 2 +- security/landlock/object.c | 14 ++++++++++++-- security/landlock/object.h | 4 ++++ security/landlock/setup.c | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/security/landlock/fs.c b/security/landlock/fs.c index fc520a06f9af..227dd67dd902 100644 --- a/security/landlock/fs.c +++ b/security/landlock/fs.c @@ -124,7 +124,7 @@ static struct landlock_object *get_inode_object(struct inode *const inode) if (unlikely(rcu_access_pointer(inode_sec->object))) { /* Someone else just created the object, bail out and retry. */ spin_unlock(&inode->i_lock); - kfree(new_object); + kmem_cache_free(landlock_object_cache, new_object); rcu_read_lock(); goto retry; diff --git a/security/landlock/object.c b/security/landlock/object.c index 1f50612f0185..df1354215617 100644 --- a/security/landlock/object.c +++ b/security/landlock/object.c @@ -17,6 +17,15 @@ #include "object.h" +struct kmem_cache *landlock_object_cache; + +void __init landlock_object_init(void) +{ + landlock_object_cache = kmem_cache_create( + "landlock_object_cache", sizeof(struct landlock_object), 0, + SLAB_PANIC, NULL); +} + struct landlock_object * landlock_create_object(const struct landlock_object_underops *const underops, void *const underobj) @@ -25,7 +34,8 @@ landlock_create_object(const struct landlock_object_underops *const underops, if (WARN_ON_ONCE(!underops || !underobj)) return ERR_PTR(-ENOENT); - new_object = kzalloc(sizeof(*new_object), GFP_KERNEL_ACCOUNT); + new_object = + kmem_cache_zalloc(landlock_object_cache, GFP_KERNEL_ACCOUNT); if (!new_object) return ERR_PTR(-ENOMEM); refcount_set(&new_object->usage, 1); @@ -62,6 +72,6 @@ void landlock_put_object(struct landlock_object *const object) * @object->underobj to @object (if it still exists). */ object->underops->release(object); - kfree_rcu(object, rcu_free); + kmem_cache_free(landlock_object_cache, object); } } diff --git a/security/landlock/object.h b/security/landlock/object.h index 5f28c35e8aa8..8ba1af3ddc2e 100644 --- a/security/landlock/object.h +++ b/security/landlock/object.h @@ -13,6 +13,10 @@ #include #include +extern struct kmem_cache *landlock_object_cache; + +void __init landlock_object_init(void); + struct landlock_object; /** diff --git a/security/landlock/setup.c b/security/landlock/setup.c index f6dd33143b7f..a5fca4582ee1 100644 --- a/security/landlock/setup.c +++ b/security/landlock/setup.c @@ -16,6 +16,7 @@ #include "net.h" #include "ptrace.h" #include "setup.h" +#include "object.h" bool landlock_initialized __ro_after_init = false; @@ -33,6 +34,7 @@ const struct lsm_id landlock_lsmid = { static int __init landlock_init(void) { + landlock_object_init(); landlock_add_cred_hooks(); landlock_add_ptrace_hooks(); landlock_add_fs_hooks(); -- 2.40.1