Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1685998pxb; Thu, 4 Mar 2021 18:48:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhhhzn8uNQt8+SBfDc3AygfwN/zymqTL6wSqm0DkmyzKYyNmAr02aXkuGZ8RIyhUJAZpER X-Received: by 2002:a17:907:b06:: with SMTP id h6mr444176ejl.144.1614912489926; Thu, 04 Mar 2021 18:48:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614912489; cv=none; d=google.com; s=arc-20160816; b=Y2wmew5dd7hPezFAZbzRGa70ONUsJuwqwQ4zCENOvrhhSc7bdkD0z99KZLEQ27I6T5 7YwpZ3AFe6hFSjnLOz2lSKFS6EI7FlPlsIvlcALY46mKh9OlaOsmFkoWrivKBmjm6XcZ K8pYTmaNsPBy6M5t/2y2emF52zaLF/GgmDSLUw1PZlwN37aBCAMwG3IUjNQeGBpsD10I xOkF+f4ScDmLmbTlnG3+xrSy25XoCiKwvp4SXOl8+IMU/cTN7LW45StsKk7BqshNqIDQ IRa1pXQiNvtek5MNpcJLc2LAlH+tiv4bEU2Mulmkn2BZXjcwnKVFgm+eJmQO990fmm9a Ae6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Yi3Usua41Hw4yIcJJb3KqUmU1Jph84h4mxzyZkzJeCo=; b=MG3ZqbsuohwG+Dz5yqZA0nIHqHh50CO6wyCi1pDXDy/nbH3zTShflECSWG39MOwu2a UfPELcCzjbN8nb71cBfYe7XZ9+KTMEbmN1GzYAEwBvJO3d4zsenPfVmsuIaU2NL7FtdW FchdL8DODRZW6F0nFMme5toLWo3KOaocU/7A7q0B3ViiV4UJkZPpDO0D7nku6l3FRumh Ve2eEBuzPmlTFKGPENanQSdIfp/DLJM2NGSEQwjo94DJGvumhlpBoLgRnPDvGOUefRzo eovZOOjdYmEYrKlQKaVZKGaM+D/zjh5MPlKvorxLKIE3Ob9cC0WmzOCFQPz6XM3AoY+C 4Ycg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WygvtXqR; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b16si552547eje.619.2021.03.04.18.47.47; Thu, 04 Mar 2021 18:48:09 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WygvtXqR; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbhCECqq (ORCPT + 99 others); Thu, 4 Mar 2021 21:46:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbhCECqq (ORCPT ); Thu, 4 Mar 2021 21:46:46 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27A44C061574; Thu, 4 Mar 2021 18:46:45 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id a24so605301plm.11; Thu, 04 Mar 2021 18:46:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Yi3Usua41Hw4yIcJJb3KqUmU1Jph84h4mxzyZkzJeCo=; b=WygvtXqRxh06GZcIZ6cm/nZmLthTdfrg1fwqfQN+iyao52zxf+H8OEtEhvvzGzsit3 AgHg9JnPzzUSi+5i3yOlhj1VmbeQ3US7lxyDFxxp/vSvcFtBDCysCNfdbk407DK7uDgS vdE2qjn+AQr+zn6Pf6F7S6x6QC/a54Cpaqpibd6meM+fYzdTxnVE+kw0IHYbWeQup9j5 ev2PPA023ik/o0smRqejzuGuQicNX8KqV3ZOMNTMfGfJ259dbgwAs81UrvSQpuBVT5QN /qBWkabd+zwaVm93GbWAk5n2PAGBBwv5vxgWE8gW0TdLcP8FlfYVAHsDLA9TDbMqOeaw LJ9w== 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:mime-version :content-transfer-encoding; bh=Yi3Usua41Hw4yIcJJb3KqUmU1Jph84h4mxzyZkzJeCo=; b=VifQ9aNXNjL9qfMApLUvSkoNyPAg1CpLrfS+CWn7s/4zV7LH2K3KZGiiPgQnsUXfSl guVF1XooquKo7e+tfH33CE7EFnE4BIwGs2bUNK7D011L8eHnh+DHdi5+gbGwbDpMkWRr F10AM3CEZaZNcIiUyQdNU0IhHIaZcpVIu7Zk1LT0swVH8WjvHKEdPRQQU8dww0bOXWUS ljCGxL6C+fSY9DEFEvLzLYG0EpB+17LCVSuGD1doLvSKmYEn75lRS98dWf0znnQ8gtuR 3KiQH2+eA8TtOSfRR/U4fDPfxIF3SLgUCRjElrBuGybUh69QB1UM510Jw5ZahYO5U1K+ jO3w== X-Gm-Message-State: AOAM533EM0F3yguPIBVKizFuTjFF1suehKBne+XLJRqom1NEaWL48LN+ 1sI91tczBZ+55D1nuxwh+7g= X-Received: by 2002:a17:90a:c20a:: with SMTP id e10mr7450856pjt.221.1614912404714; Thu, 04 Mar 2021 18:46:44 -0800 (PST) Received: from localhost.localdomain ([103.114.158.1]) by smtp.gmail.com with ESMTPSA id 197sm254861pfc.1.2021.03.04.18.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 18:46:44 -0800 (PST) From: Jiele zhao To: keescook@chromium.org Cc: jmorris@namei.org, serge@hallyn.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Jiele zhao Subject: [PATCH v2] security/loadpin: Replace "kernel_read_file_str[j]" with function "kernel_read_file_id_str(j)". Date: Fri, 5 Mar 2021 02:46:02 +0000 Message-Id: <20210305024602.203217-1-unclexiaole@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Actually Linux kernel already provide function "kernel_read_file_id_str()" for secure access in "kernel_read_file.h". And, in "parse_exclude()" function, it's better to use BUILD_BUG_ON(ARRAY_SIZE(kernel_read_file_str) - 1 == ARRAY_SIZE(ignore_read_file_id)); to make sure the arrays stay within expected sizes. Signed-off-by: Jiele zhao --- security/loadpin/loadpin.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c index b12f7d986b1e..3d59ff363087 100644 --- a/security/loadpin/loadpin.c +++ b/security/loadpin/loadpin.c @@ -210,9 +210,10 @@ static void __init parse_exclude(void) */ BUILD_BUG_ON(ARRAY_SIZE(exclude_read_files) != ARRAY_SIZE(ignore_read_file_id)); - BUILD_BUG_ON(ARRAY_SIZE(kernel_read_file_str) < + BUILD_BUG_ON(ARRAY_SIZE(kernel_read_file_str) - 1 == ARRAY_SIZE(ignore_read_file_id)); + for (i = 0; i < ARRAY_SIZE(exclude_read_files); i++) { cur = exclude_read_files[i]; if (!cur) @@ -221,9 +222,9 @@ static void __init parse_exclude(void) continue; for (j = 0; j < ARRAY_SIZE(ignore_read_file_id); j++) { - if (strcmp(cur, kernel_read_file_str[j]) == 0) { + if (strcmp(cur, kernel_read_file_id_str(j)) == 0) { pr_info("excluding: %s\n", - kernel_read_file_str[j]); + kernel_read_file_id_str(j)); ignore_read_file_id[j] = 1; /* * Can not break, because one read_file_str -- 2.25.1