diff mbox series

[V2] dmicheck: skip scanning smbios in /dev/mem on aarch64

Message ID 20211110202504.507536-1-alex.hung@canonical.com
State Superseded
Headers show
Series [V2] dmicheck: skip scanning smbios in /dev/mem on aarch64 | expand

Commit Message

Alex Hung Nov. 10, 2021, 8:25 p.m. UTC
Buglink: https://bugs.launchpad.net/bugs/1947786

Signed-off-by: Alex Hung <alex.hung@canonical.com>
---
 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

Comments

Sunny Wang Nov. 11, 2021, 9:39 p.m. UTC | #1
Looks good to me. Thanks, Alex.
Reviewed-by: Sunny Wang <sunny.wang@arm.com>

-----Original Message-----
From: Alex Hung <alex.hung@canonical.com>
Sent: 10 November 2021 20:25
To: fwts-devel@lists.ubuntu.com; Sunny Wang <Sunny.Wang@arm.com>; G Edhaya Chandran <Edhaya.Chandran@arm.com>
Cc: Alex Hung <alex.hung@canonical.com>
Subject: [PATCH][V2] dmicheck: skip scanning smbios in /dev/mem on aarch64

Buglink: https://bugs.launchpad.net/bugs/1947786

Signed-off-by: Alex Hung <alex.hung@canonical.com>
---
 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 <sys/utsname.h>
+
+#include "fwts.h"
+#include "fwts_kernel.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <bsd/string.h>
+
+#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;
+}
--
2.32.0

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Ivan Hu Nov. 15, 2021, 8:44 a.m. UTC | #2
On 11/11/21 4:25 AM, Alex Hung wrote:
> Buglink: https://bugs.launchpad.net/bugs/1947786
> 
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  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"
Is it better to print out some information here?
> +		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"))
same here.

Ivan
> +		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 <sys/utsname.h>
> +
> +#include "fwts.h"
> +#include "fwts_kernel.h"
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <bsd/string.h>
> +
> +#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;
> +}
>
diff mbox series

Patch

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 <sys/utsname.h>
+
+#include "fwts.h"
+#include "fwts_kernel.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <bsd/string.h>
+
+#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;
+}