From patchwork Wed Nov 10 20:25:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Hung X-Patchwork-Id: 1553588 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=cBffFnag; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HqGYt60s4z9s1l for ; Thu, 11 Nov 2021 07:25:21 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1mku9g-00055z-1a; Wed, 10 Nov 2021 20:25:12 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1mku9e-00055s-3S for fwts-devel@lists.ubuntu.com; Wed, 10 Nov 2021 20:25:10 +0000 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id C6B8B3F19F for ; Wed, 10 Nov 2021 20:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1636575908; bh=SGMjwyxdpD2LaNLkwe9k5uVhbsaaZWbNbo6475D/Qs0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=cBffFnagfeeYjoGJmkvJF7WfCP5SRzje9Klcw+0d/9MLEumBGtfbKQ0gvL8s0WSIn +9OycqQV8FdrnOdV+YTzjpXkRcHZbDETruAnAkGcUYuoLvEH3U9chgp0HAhhSomnPa I0uVkp9uvMVJM/WReJjtGFHVUtHfsSECAm8oe2QTkWvReex5dCeowefFmTCErs+waz EGibynpciBECbpH4nEX0UXfZX8HsT4t+MfB2qzml4eN+Skmui8ORmRcKEJLBaQkcIL m4lbVnFY+hGfA+9EudXwZCQq7suSylhlw2m0cajgTWcP6VbvT5kqMludSYkwZkUFBd DxuycqMwvubZg== Received: by mail-pj1-f70.google.com with SMTP id p12-20020a17090b010c00b001a65bfe8054so1654436pjz.8 for ; Wed, 10 Nov 2021 12:25:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SGMjwyxdpD2LaNLkwe9k5uVhbsaaZWbNbo6475D/Qs0=; b=mOeT7NzRbTJxp6a5GoSDIWFhZQEZPxDwZO2ctXnqjaCcM/E6BLoHzpAaqYHwUlW4Wk TDrrfYVOQmnGP7P53ragwH7lAhUfM1oY4sx5Nld2vIWk28bOBsH+ZAH0EdI6KxgstEGN 1k0hMUtI2UWaSuRB1sP5jZNQLqbWqhiSUo8AXO33W6NOzdsC4SV/k/pzBy9ZoIH28QUB enOz1GzV5E6Z09KpTnrmnLTUJ1y2rPKBc1bLngECKnHdmH8hAfY+5kPhOjOjXruLrry+ whx7rrQwBpgrh0qopqxKzyedrf2dEbyyf10WHjQqOLoMOipvWXmLLJCkDPn7/TSkzFjb gHVQ== X-Gm-Message-State: AOAM5336AtJYxSmHMFNE9fQb/0k+kHx3xS1HrvbvUpPzNELfpWlo065u a4xpZfsVibDwalHaMP2IsVA0aN2CPFMozfj34zVrFA0doRsvYQzRBzHcrF4PRz0WVwOdptEBPy1 sE10m6jqTozudt4rK6QokhcsR7VUXLXh/7zDnxIxB X-Received: by 2002:a17:90a:c78f:: with SMTP id gn15mr20029390pjb.54.1636575906908; Wed, 10 Nov 2021 12:25:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyDphc3+bq0+hyvejtCvvffMne+sYvvWEyrafudK4Xbuy98UFxFC6k+7a9H4j7OVZJrxlt2jA== X-Received: by 2002:a17:90a:c78f:: with SMTP id gn15mr20029322pjb.54.1636575906363; Wed, 10 Nov 2021 12:25:06 -0800 (PST) Received: from canonical.com (node-1w7jr9yebujeq5th4a1ypmet6.ipv6.telus.net. [2001:56a:78ed:fb00::57a]) by smtp.gmail.com with ESMTPSA id l1sm6290618pjh.28.2021.11.10.12.25.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 12:25:05 -0800 (PST) From: Alex Hung To: fwts-devel@lists.ubuntu.com, Sunny.Wang@arm.com, Edhaya.Chandran@arm.com Subject: [PATCH][V2] dmicheck: skip scanning smbios in /dev/mem on aarch64 Date: Wed, 10 Nov 2021 13:25:04 -0700 Message-Id: <20211110202504.507536-1-alex.hung@canonical.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" Buglink: https://bugs.launchpad.net/bugs/1947786 Signed-off-by: Alex Hung Reviewed-by: Sunny Wang Signed-off-by: Alex Hung --- src/dmi/dmicheck/dmicheck.c | 10 +++++ src/lib/include/fwts.h | 1 + src/lib/include/fwts_kernel.h | 25 ++++++++++++ src/lib/src/Makefile.am | 1 + src/lib/src/fwts_kernel.c | 74 +++++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 src/lib/include/fwts_kernel.h create mode 100644 src/lib/src/fwts_kernel.c diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c index 7f6a90c4..67715687 100644 --- a/src/dmi/dmicheck/dmicheck.c +++ b/src/dmi/dmicheck/dmicheck.c @@ -381,6 +381,11 @@ static void* dmi_table_smbios(fwts_framework *fw, fwts_smbios_entry *entry) free(table); } +#ifdef FWTS_ARCH_AARCH64 + if (fwts_kernel_config_set("CONFIG_STRICT_DEVMEM")) + return NULL; +#endif + mem = fwts_mmap(addr, length); if (mem != FWTS_MAP_FAILED) { /* Can we safely copy the table? */ @@ -429,6 +434,11 @@ static void* dmi_table_smbios30(fwts_framework *fw, fwts_smbios30_entry *entry) free(table); } +#ifdef FWTS_ARCH_AARCH64 + if (fwts_kernel_config_set("CONFIG_STRICT_DEVMEM")) + return NULL; +#endif + mem = fwts_mmap(addr, length); if (mem != FWTS_MAP_FAILED) { /* Can we safely copy the table? */ diff --git a/src/lib/include/fwts.h b/src/lib/include/fwts.h index 551a4e09..be754a99 100644 --- a/src/lib/include/fwts.h +++ b/src/lib/include/fwts.h @@ -185,6 +185,7 @@ #include "fwts_iasl.h" #include "fwts_ipmi.h" #include "fwts_klog.h" +#include "fwts_kernel.h" #include "fwts_olog.h" #include "fwts_pipeio.h" #include "fwts_stringextras.h" diff --git a/src/lib/include/fwts_kernel.h b/src/lib/include/fwts_kernel.h new file mode 100644 index 00000000..a89576ae --- /dev/null +++ b/src/lib/include/fwts_kernel.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2021 Canonical + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef __FWTS_KERNEL_H__ +#define __FWTS_KERNEL_H__ + +bool fwts_kernel_config_set(const char *config); + +#endif diff --git a/src/lib/src/Makefile.am b/src/lib/src/Makefile.am index 55c52b41..0a39882a 100644 --- a/src/lib/src/Makefile.am +++ b/src/lib/src/Makefile.am @@ -83,6 +83,7 @@ libfwts_la_SOURCES = \ fwts_ioport.c \ fwts_ipmi.c \ fwts_json.c \ + fwts_kernel.c \ fwts_keymap.c \ fwts_klog.c \ fwts_olog.c \ diff --git a/src/lib/src/fwts_kernel.c b/src/lib/src/fwts_kernel.c new file mode 100644 index 00000000..10d11a99 --- /dev/null +++ b/src/lib/src/fwts_kernel.c @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2021 Canonical + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include + +#include "fwts.h" +#include "fwts_kernel.h" +#include +#include +#include + +#define CONFIG_FILE_PREFIX "/boot/config-" + +/* + * fwts_kernel_config_set + * check whether a kernel config is set, ex. + * true if CONFIG_XYZ=y or CONFIG_XYZ=m + */ +bool fwts_kernel_config_set(const char *config) +{ + const size_t config_str_len = strlen(config) + 3; + char config_file[PATH_MAX]; + char config_str[255]; + size_t config_file_len; + fwts_list* config_list; + fwts_list_link *item; + struct utsname buf; + + /* get path of config file, i.e. /boot/config-5.11.0-38-generic */ + uname(&buf); + config_file_len = strlen(CONFIG_FILE_PREFIX) + strlen(buf.release) + 1; + (void)strlcpy(config_file, CONFIG_FILE_PREFIX, config_file_len); + (void)strlcat(config_file, buf.release, config_file_len); + + config_list = fwts_file_open_and_read(config_file); + if (config_list == NULL) + return false; + + fwts_list_foreach(item, config_list) { + /* check built-in, i.e. =y */ + (void)strlcpy(config_str, config, config_str_len); + (void)strlcat(config_str, "=y", config_str_len); + if (!strncmp(fwts_text_list_text(item), config_str, strlen(config_str))) { + fwts_list_free(config_list, free); + return true; + } + + /* check module, i.e. =m */ + config_str[strlen(config_str) - 1] = 'm'; + if (!strncmp(fwts_text_list_text(item), config_str, strlen(config_str))) { + fwts_list_free(config_list, free); + return true; + } + } + + fwts_list_free(config_list, free); + return false; +}