Skip to contentSkip to conversation

makedumpfile/s390: Add get_kaslr_offset() for s390x

PATCH In review Mikhail Zaslonko 4 participants 10 messages Dec 3, 2019 – Dec 30, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 makedumpfile/s390: Add get_kaslr_offset() for s390x

Since kernel v5.2 KASLR is supported on s390. In makedumpfile however no support has been added yet. This patch adds the arch specific function get_kaslr_offset() for s390x.
Since the values in vmcoreinfo are already relocated, the patch is mainly relevant for vmlinux processing (-x option).

---
 arch/s390x.c   | 32 ++++++++++++++++++++++++++++++++
 makedumpfile.h |  3 ++-
 2 files changed, 34 insertions(+), 1 deletion(-)
arch/s390x.c +32 -0
index bf9d58e..892df14 100644
@@ -122,6 +122,38 @@ get_machdep_info_s390x(void)
 	return TRUE;
 }
 
+unsigned long
+get_kaslr_offset_s390x(unsigned long vaddr)
+{
+	unsigned int i;
+	char buf[BUFSIZE_FGETS], *endp;
+
+	if (!info->file_vmcoreinfo)
+		return FALSE;
+
+	if (fseek(info->file_vmcoreinfo, 0, SEEK_SET) < 0) {
+		ERRMSG("Can't seek the vmcoreinfo file(%s). %s\n",
+		       info->name_vmcoreinfo, strerror(errno));
+		return FALSE;
+	}
+
+	while (fgets(buf, BUFSIZE_FGETS, info->file_vmcoreinfo)) {
+		i = strlen(buf);
+		if (!i)
+			break;
+		if (buf[i - 1] == '\n')
+			buf[i - 1] = '\0';
+		if (strncmp(buf, STR_KERNELOFFSET,
+			    strlen(STR_KERNELOFFSET)) == 0) {
+			info->kaslr_offset =
+				strtoul(buf + strlen(STR_KERNELOFFSET), &endp, 16);
+			DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
+		}
+	}
+
+	return info->kaslr_offset;
+}
+
 static int
 is_vmalloc_addr_s390x(unsigned long vaddr)
 {
makedumpfile.h +2 -1
index ac11e90..26f6247 100644
@@ -1071,11 +1071,12 @@ unsigned long long vaddr_to_paddr_ppc(unsigned long vaddr);
 int get_machdep_info_s390x(void);
 unsigned long long vaddr_to_paddr_s390x(unsigned long vaddr);
 int is_iomem_phys_addr_s390x(unsigned long addr);
+unsigned long get_kaslr_offset_s390x(unsigned long vaddr);
 #define find_vmemmap()		stub_false()
 #define get_phys_base()		stub_true()
 #define get_machdep_info()	get_machdep_info_s390x()
 #define get_versiondep_info()	stub_true()
-#define get_kaslr_offset(X)	stub_false()
+#define get_kaslr_offset(X)	get_kaslr_offset_s390x(X)
 #define vaddr_to_paddr(X)	vaddr_to_paddr_s390x(X)
 #define paddr_to_vaddr(X)	paddr_to_vaddr_general(X)
 #define is_phys_addr(X)		is_iomem_phys_addr_s390x(X)
Signature · 7 lines
2.17.1


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw

Hi Mikhail,

Sorry for late reply.

Quoted 6 lines

-----Original Message-----
Since kernel v5.2 KASLR is supported on s390. In makedumpfile however no support has been added yet. This patch adds the arch specific function get_kaslr_offset() for s390x.
Since the values in vmcoreinfo are already relocated, the patch is mainly relevant for vmlinux processing (-x option).

In the current implementation of makedumpfile, the get_kaslr_offset(vaddr) is supposed to return the KASLR offset only when the offset is needed to add to the vaddr. So generally symbols from kernel (vmlinux) need it, but symbols from modules are resolved dynamically and don't need the offset.

This patch always returns the offset if any, as a result, I guess this patch will not work as expected with module symbols in filter config file.

So... How about making get_kaslr_offset_arm64() general for other archs (get_kaslr_offset_general() or something), then using it also for s390? If OK, I can do that generalization.

Thanks,
Kazu

Quoted 70 lines
---
 arch/s390x.c   | 32 ++++++++++++++++++++++++++++++++
 makedumpfile.h |  3 ++-
 2 files changed, 34 insertions(+), 1 deletion(-)
arch/s390x.c +32 -0
index bf9d58e..892df14 100644
@@ -122,6 +122,38 @@ get_machdep_info_s390x(void)
 	return TRUE;
 }
 
+unsigned long
+get_kaslr_offset_s390x(unsigned long vaddr)
+{
+	unsigned int i;
+	char buf[BUFSIZE_FGETS], *endp;
+
+	if (!info->file_vmcoreinfo)
+		return FALSE;
+
+	if (fseek(info->file_vmcoreinfo, 0, SEEK_SET) < 0) {
+		ERRMSG("Can't seek the vmcoreinfo file(%s). %s\n",
+		       info->name_vmcoreinfo, strerror(errno));
+		return FALSE;
+	}
+
+	while (fgets(buf, BUFSIZE_FGETS, info->file_vmcoreinfo)) {
+		i = strlen(buf);
+		if (!i)
+			break;
+		if (buf[i - 1] == '\n')
+			buf[i - 1] = '\0';
+		if (strncmp(buf, STR_KERNELOFFSET,
+			    strlen(STR_KERNELOFFSET)) == 0) {
+			info->kaslr_offset =
+				strtoul(buf + strlen(STR_KERNELOFFSET), &endp, 16);
+			DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
+		}
+	}
+
+	return info->kaslr_offset;
+}
+
 static int
 is_vmalloc_addr_s390x(unsigned long vaddr)
 {
makedumpfile.h +2 -2
index ac11e90..26f6247 100644
@@ -1071,11 +1071,12 @@ unsigned long long vaddr_to_paddr_ppc(unsigned long vaddr);
 int get_machdep_info_s390x(void);
 unsigned long long vaddr_to_paddr_s390x(unsigned long vaddr);
 int is_iomem_phys_addr_s390x(unsigned long addr);
+unsigned long get_kaslr_offset_s390x(unsigned long vaddr);
 #define find_vmemmap()		stub_false()
 #define get_phys_base()		stub_true()
 #define get_machdep_info()	get_machdep_info_s390x()
 #define get_versiondep_info()	stub_true()
-#define get_kaslr_offset(X)	stub_false()
+#define get_kaslr_offset(X)	get_kaslr_offset_s390x(X)
 #define vaddr_to_paddr(X)	vaddr_to_paddr_s390x(X)
 #define paddr_to_vaddr(X)	paddr_to_vaddr_general(X)
 #define is_phys_addr(X)		is_iomem_phys_addr_s390x(X)
--
Quoted 2 lines

2.17.1

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw

Hello Kazu,

I think we can try to generalize the kaslr offset extraction.
I won't speak for other architectures, but for s390 that get_kaslr_offset_arm64() should work fine. The only concern of mine is this TODO statement:

if (_text <= vaddr && vaddr <= _end) {
	DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
	return info->kaslr_offset;
	} else {
	/*
	* TODO: we need to check if it is vmalloc/vmmemmap/module
	* address, we will have different offset
	*/
	return 0;
}

Could you explain this one?

Thanks,
Mikhail

Quoted 11 lines · Kazuhito Hagio

Hi Mikhail,

Sorry for late reply.

Quoted 6 lines

-----Original Message-----
Since kernel v5.2 KASLR is supported on s390. In makedumpfile however no support has been added yet. This patch adds the arch specific function get_kaslr_offset() for s390x.
Since the values in vmcoreinfo are already relocated, the patch is mainly relevant for vmlinux processing (-x option).

Quoted 4 lines

In the current implementation of makedumpfile, the get_kaslr_offset(vaddr) is supposed to return the KASLR offset only when the offset is needed to add to the vaddr. So generally symbols from kernel (vmlinux) need it, but symbols from modules are resolved dynamically and don't need the offset.

\>

Quoted 74 lines

This patch always returns the offset if any, as a result, I guess this patch will not work as expected with module symbols in filter config file.

So... How about making get_kaslr_offset_arm64() general for other archs (get_kaslr_offset_general() or something), then using it also for s390? If OK, I can do that generalization.

Thanks,
Kazu

Quoted 64 lines
---
 arch/s390x.c   | 32 ++++++++++++++++++++++++++++++++
 makedumpfile.h |  3 ++-
 2 files changed, 34 insertions(+), 1 deletion(-)
arch/s390x.c +32 -0
index bf9d58e..892df14 100644
@@ -122,6 +122,38 @@ get_machdep_info_s390x(void)
 	return TRUE;
 }
 
+unsigned long
+get_kaslr_offset_s390x(unsigned long vaddr)
+{
+	unsigned int i;
+	char buf[BUFSIZE_FGETS], *endp;
+
+	if (!info->file_vmcoreinfo)
+		return FALSE;
+
+	if (fseek(info->file_vmcoreinfo, 0, SEEK_SET) < 0) {
+		ERRMSG("Can't seek the vmcoreinfo file(%s). %s\n",
+		       info->name_vmcoreinfo, strerror(errno));
+		return FALSE;
+	}
+
+	while (fgets(buf, BUFSIZE_FGETS, info->file_vmcoreinfo)) {
+		i = strlen(buf);
+		if (!i)
+			break;
+		if (buf[i - 1] == '\n')
+			buf[i - 1] = '\0';
+		if (strncmp(buf, STR_KERNELOFFSET,
+			    strlen(STR_KERNELOFFSET)) == 0) {
+			info->kaslr_offset =
+				strtoul(buf + strlen(STR_KERNELOFFSET), &endp, 16);
+			DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
+		}
+	}
+
+	return info->kaslr_offset;
+}
+
 static int
 is_vmalloc_addr_s390x(unsigned long vaddr)
 {
makedumpfile.h +1 -0
index ac11e90..26f6247 100644
@@ -1071,11 +1071,12 @@ unsigned long long vaddr_to_paddr_ppc(unsigned long vaddr);
 int get_machdep_info_s390x(void);
 unsigned long long vaddr_to_paddr_s390x(unsigned long vaddr);
 int is_iomem_phys_addr_s390x(unsigned long addr);
+unsigned long get_kaslr_offset_s390x(unsigned long vaddr);
 #define find_vmemmap()		stub_false()
 #define get_phys_base()		stub_true()
 #define get_machdep_info()	get_machdep_info_s390x()
 #define get_versiondep_info()	stub_true()
Quoted 10 lines
Quoted 8 lines
makedumpfile.h +1 -2
-#define get_kaslr_offset(X)	stub_false()
+#define get_kaslr_offset(X)	get_kaslr_offset_s390x(X)
 #define vaddr_to_paddr(X)	vaddr_to_paddr_s390x(X)
 #define paddr_to_vaddr(X)	paddr_to_vaddr_general(X)
 #define is_phys_addr(X)		is_iomem_phys_addr_s390x(X)
--

2.17.1

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw

Hi Mikhail,

Quoted 18 lines

-----Original Message-----
Hello Kazu,

I think we can try to generalize the kaslr offset extraction.
I won't speak for other architectures, but for s390 that get_kaslr_offset_arm64() should work fine. The only concern of mine is this TODO statement:

if (_text <= vaddr && vaddr <= _end) {
	DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
	return info->kaslr_offset;
	} else {
	/*
	* TODO: we need to check if it is vmalloc/vmmemmap/module
	* address, we will have different offset
	*/
	return 0;
}
Quoted 1 line

Could you explain this one?

Probably it was considered that the check would be needed to support the whole KASLR behavior when get_kaslr_offset_x86_64() was written originally.

But in the current makedumpfile for x86_64 and arm64 supporting KASLR, the offset we need is the one for symbol addresses in vmlinux only. As I said below, module symbol addresses are retrieved from vmcore. Other addresses should not be passed to the function for now, as far as I know.

So I think the TODO comment is confusing, and it would be better to remove it or change it to something like:
/*
* Returns 0 if vaddr does not need the offset to be added,
* e.g. for module address.
*/

But if s390 uses get_kaslr_offset() in its arch-specific code to adjust addresses other than kernel text address, we might need to modify it for s390, not generalize it.

Thanks,
Kazu

Quoted 16 lines

Thanks,
Mikhail

Quoted 11 lines · Kazuhito Hagio

Hi Mikhail,

Sorry for late reply.

Quoted 6 lines

-----Original Message-----
Since kernel v5.2 KASLR is supported on s390. In makedumpfile however no support has been added yet. This patch adds the arch specific function get_kaslr_offset() for s390x.
Since the values in vmcoreinfo are already relocated, the patch is mainly relevant for vmlinux processing (-x option).

Quoted 89 lines
Quoted 4 lines

In the current implementation of makedumpfile, the get_kaslr_offset(vaddr) is supposed to return the KASLR offset only when the offset is needed to add to the vaddr. So generally symbols from kernel (vmlinux) need it, but symbols from modules are resolved dynamically and don't need the offset.

\>

Quoted 84 lines

This patch always returns the offset if any, as a result, I guess this patch will not work as expected with module symbols in filter config file.

So... How about making get_kaslr_offset_arm64() general for other archs (get_kaslr_offset_general() or something), then using it also for s390? If OK, I can do that generalization.

Thanks,
Kazu

Quoted 72 lines
---
 arch/s390x.c   | 32 ++++++++++++++++++++++++++++++++
 makedumpfile.h |  3 ++-
 2 files changed, 34 insertions(+), 1 deletion(-)
arch/s390x.c +32 -0
index bf9d58e..892df14 100644
@@ -122,6 +122,38 @@ get_machdep_info_s390x(void)
 	return TRUE;
 }
 
+unsigned long
+get_kaslr_offset_s390x(unsigned long vaddr)
+{
+	unsigned int i;
+	char buf[BUFSIZE_FGETS], *endp;
+
+	if (!info->file_vmcoreinfo)
+		return FALSE;
+
+	if (fseek(info->file_vmcoreinfo, 0, SEEK_SET) < 0) {
+		ERRMSG("Can't seek the vmcoreinfo file(%s). %s\n",
+		       info->name_vmcoreinfo, strerror(errno));
+		return FALSE;
+	}
+
+	while (fgets(buf, BUFSIZE_FGETS, info->file_vmcoreinfo)) {
+		i = strlen(buf);
+		if (!i)
+			break;
+		if (buf[i - 1] == '\n')
+			buf[i - 1] = '\0';
+		if (strncmp(buf, STR_KERNELOFFSET,
+			    strlen(STR_KERNELOFFSET)) == 0) {
+			info->kaslr_offset =
+				strtoul(buf + strlen(STR_KERNELOFFSET), &endp, 16);
+			DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
+		}
+	}
+
+	return info->kaslr_offset;
+}
+
 static int
 is_vmalloc_addr_s390x(unsigned long vaddr)
 {
makedumpfile.h +2 -2
index ac11e90..26f6247 100644
@@ -1071,11 +1071,12 @@ unsigned long long vaddr_to_paddr_ppc(unsigned long vaddr);
 int get_machdep_info_s390x(void);
 unsigned long long vaddr_to_paddr_s390x(unsigned long vaddr);
 int is_iomem_phys_addr_s390x(unsigned long addr);
+unsigned long get_kaslr_offset_s390x(unsigned long vaddr);
 #define find_vmemmap()		stub_false()
 #define get_phys_base()		stub_true()
 #define get_machdep_info()	get_machdep_info_s390x()
 #define get_versiondep_info()	stub_true()
-#define get_kaslr_offset(X)	stub_false()
+#define get_kaslr_offset(X)	get_kaslr_offset_s390x(X)
 #define vaddr_to_paddr(X)	vaddr_to_paddr_s390x(X)
 #define paddr_to_vaddr(X)	paddr_to_vaddr_general(X)
 #define is_phys_addr(X)		is_iomem_phys_addr_s390x(X)
--

2.17.1

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw

Hi,

Quoted 39 lines · Kazuhito Hagio

Hi Mikhail,

Quoted 18 lines

-----Original Message-----
Hello Kazu,

I think we can try to generalize the kaslr offset extraction.
I won't speak for other architectures, but for s390 that get_kaslr_offset_arm64() should work fine. The only concern of mine is this TODO statement:

if (_text <= vaddr && vaddr <= _end) {
	DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
	return info->kaslr_offset;
	} else {
	/*
	* TODO: we need to check if it is vmalloc/vmmemmap/module
	* address, we will have different offset
	*/
	return 0;
}
Quoted 1 line

Could you explain this one?

Probably it was considered that the check would be needed to support the whole KASLR behavior when get_kaslr_offset_x86_64() was written originally.

But in the current makedumpfile for x86_64 and arm64 supporting KASLR, the offset we need is the one for symbol addresses in vmlinux only. As I said below, module symbol addresses are retrieved from vmcore. Other addresses should not be passed to the function for now, as far as I know.

So I think the TODO comment is confusing, and it would be better to remove it or change it to something like:
/*
* Returns 0 if vaddr does not need the offset to be added,
* e.g. for module address.
*/

Quoted 3 lines

But if s390 uses get_kaslr_offset() in its arch-specific code to adjust addresses other than kernel text address, we might need to modify it for s390, not generalize it.

Currently, s390 doesn't use get_kaslr_offset() in its arch-specific code.

Quoted 111 lines

Thanks,
Kazu

Quoted 105 lines

Thanks,
Mikhail

Quoted 11 lines · Kazuhito Hagio

Hi Mikhail,

Sorry for late reply.

Quoted 6 lines

-----Original Message-----
Since kernel v5.2 KASLR is supported on s390. In makedumpfile however no support has been added yet. This patch adds the arch specific function get_kaslr_offset() for s390x.
Since the values in vmcoreinfo are already relocated, the patch is mainly relevant for vmlinux processing (-x option).

Quoted 4 lines

In the current implementation of makedumpfile, the get_kaslr_offset(vaddr) is supposed to return the KASLR offset only when the offset is needed to add to the vaddr. So generally symbols from kernel (vmlinux) need it, but symbols from modules are resolved dynamically and don't need the offset.

\>

Quoted 84 lines

This patch always returns the offset if any, as a result, I guess this patch will not work as expected with module symbols in filter config file.

So... How about making get_kaslr_offset_arm64() general for other archs (get_kaslr_offset_general() or something), then using it also for s390? If OK, I can do that generalization.

Thanks,
Kazu

Quoted 72 lines
---
 arch/s390x.c   | 32 ++++++++++++++++++++++++++++++++
 makedumpfile.h |  3 ++-
 2 files changed, 34 insertions(+), 1 deletion(-)
arch/s390x.c +32 -0
index bf9d58e..892df14 100644
@@ -122,6 +122,38 @@ get_machdep_info_s390x(void)
 	return TRUE;
 }
 
+unsigned long
+get_kaslr_offset_s390x(unsigned long vaddr)
+{
+	unsigned int i;
+	char buf[BUFSIZE_FGETS], *endp;
+
+	if (!info->file_vmcoreinfo)
+		return FALSE;
+
+	if (fseek(info->file_vmcoreinfo, 0, SEEK_SET) < 0) {
+		ERRMSG("Can't seek the vmcoreinfo file(%s). %s\n",
+		       info->name_vmcoreinfo, strerror(errno));
+		return FALSE;
+	}
+
+	while (fgets(buf, BUFSIZE_FGETS, info->file_vmcoreinfo)) {
+		i = strlen(buf);
+		if (!i)
+			break;
+		if (buf[i - 1] == '\n')
+			buf[i - 1] = '\0';
+		if (strncmp(buf, STR_KERNELOFFSET,
+			    strlen(STR_KERNELOFFSET)) == 0) {
+			info->kaslr_offset =
+				strtoul(buf + strlen(STR_KERNELOFFSET), &endp, 16);
+			DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
+		}
+	}
+
+	return info->kaslr_offset;
+}
+
 static int
 is_vmalloc_addr_s390x(unsigned long vaddr)
 {
makedumpfile.h +2 -2
index ac11e90..26f6247 100644
@@ -1071,11 +1071,12 @@ unsigned long long vaddr_to_paddr_ppc(unsigned long vaddr);
 int get_machdep_info_s390x(void);
 unsigned long long vaddr_to_paddr_s390x(unsigned long vaddr);
 int is_iomem_phys_addr_s390x(unsigned long addr);
+unsigned long get_kaslr_offset_s390x(unsigned long vaddr);
 #define find_vmemmap()		stub_false()
 #define get_phys_base()		stub_true()
 #define get_machdep_info()	get_machdep_info_s390x()
 #define get_versiondep_info()	stub_true()
-#define get_kaslr_offset(X)	stub_false()
+#define get_kaslr_offset(X)	get_kaslr_offset_s390x(X)
 #define vaddr_to_paddr(X)	vaddr_to_paddr_s390x(X)
 #define paddr_to_vaddr(X)	paddr_to_vaddr_general(X)
 #define is_phys_addr(X)		is_iomem_phys_addr_s390x(X)
--

2.17.1

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#5 lore raw

Hi Mikhail,

Quoted 43 lines

-----Original Message-----
Hi,

Quoted 39 lines · Kazuhito Hagio

Hi Mikhail,

Quoted 18 lines

-----Original Message-----
Hello Kazu,

I think we can try to generalize the kaslr offset extraction.
I won't speak for other architectures, but for s390 that get_kaslr_offset_arm64() should work fine. The only concern of mine is this TODO statement:

if (_text <= vaddr && vaddr <= _end) {
	DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
	return info->kaslr_offset;
	} else {
	/*
	* TODO: we need to check if it is vmalloc/vmmemmap/module
	* address, we will have different offset
	*/
	return 0;
}
Quoted 1 line

Could you explain this one?

Probably it was considered that the check would be needed to support the whole KASLR behavior when get_kaslr_offset_x86_64() was written originally.

But in the current makedumpfile for x86_64 and arm64 supporting KASLR, the offset we need is the one for symbol addresses in vmlinux only. As I said below, module symbol addresses are retrieved from vmcore. Other addresses should not be passed to the function for now, as far as I know.

So I think the TODO comment is confusing, and it would be better to remove it or change it to something like:
/*
* Returns 0 if vaddr does not need the offset to be added,
* e.g. for module address.
*/

Quoted 6 lines
Quoted 3 lines

But if s390 uses get_kaslr_offset() in its arch-specific code to adjust addresses other than kernel text address, we might need to modify it for s390, not generalize it.

Currently, s390 doesn't use get_kaslr_offset() in its arch-specific code.

OK, I pushed a patch that generalizes it to my test repository. Could you enable s390 to use it and test?
https://github.com/k-hagio/makedumpfile/tree/add-get_kaslr_offset_general

Thanks,
Kazu

Quoted 104 lines
Quoted 104 lines

Thanks,
Kazu

Quoted 99 lines

Thanks,
Mikhail

Quoted 11 lines · Kazuhito Hagio

Hi Mikhail,

Sorry for late reply.

Quoted 6 lines

-----Original Message-----
Since kernel v5.2 KASLR is supported on s390. In makedumpfile however no support has been added yet. This patch adds the arch specific function get_kaslr_offset() for s390x.
Since the values in vmcoreinfo are already relocated, the patch is mainly relevant for vmlinux processing (-x option).

Quoted 4 lines

In the current implementation of makedumpfile, the get_kaslr_offset(vaddr) is supposed to return the KASLR offset only when the offset is needed to add to the vaddr. So generally symbols from kernel (vmlinux) need it, but symbols from modules are resolved dynamically and don't need the offset.

\>

Quoted 78 lines

This patch always returns the offset if any, as a result, I guess this patch will not work as expected with module symbols in filter config file.

So... How about making get_kaslr_offset_arm64() general for other archs (get_kaslr_offset_general() or something), then using it also for s390? If OK, I can do that generalization.

Thanks,
Kazu

Quoted 68 lines
---
 arch/s390x.c   | 32 ++++++++++++++++++++++++++++++++
 makedumpfile.h |  3 ++-
 2 files changed, 34 insertions(+), 1 deletion(-)
arch/s390x.c +32 -0
index bf9d58e..892df14 100644
@@ -122,6 +122,38 @@ get_machdep_info_s390x(void)
 	return TRUE;
 }
 
+unsigned long
+get_kaslr_offset_s390x(unsigned long vaddr)
+{
+	unsigned int i;
+	char buf[BUFSIZE_FGETS], *endp;
+
+	if (!info->file_vmcoreinfo)
+		return FALSE;
+
+	if (fseek(info->file_vmcoreinfo, 0, SEEK_SET) < 0) {
+		ERRMSG("Can't seek the vmcoreinfo file(%s). %s\n",
+		       info->name_vmcoreinfo, strerror(errno));
+		return FALSE;
+	}
+
+	while (fgets(buf, BUFSIZE_FGETS, info->file_vmcoreinfo)) {
+		i = strlen(buf);
+		if (!i)
+			break;
+		if (buf[i - 1] == '\n')
+			buf[i - 1] = '\0';
+		if (strncmp(buf, STR_KERNELOFFSET,
+			    strlen(STR_KERNELOFFSET)) == 0) {
+			info->kaslr_offset =
+				strtoul(buf + strlen(STR_KERNELOFFSET), &endp, 16);
+			DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
+		}
+	}
+
+	return info->kaslr_offset;
+}
+
 static int
 is_vmalloc_addr_s390x(unsigned long vaddr)
 {
makedumpfile.h +2 -1
index ac11e90..26f6247 100644
@@ -1071,11 +1071,12 @@ unsigned long long vaddr_to_paddr_ppc(unsigned long vaddr);
 int get_machdep_info_s390x(void);
 unsigned long long vaddr_to_paddr_s390x(unsigned long vaddr);
 int is_iomem_phys_addr_s390x(unsigned long addr);
+unsigned long get_kaslr_offset_s390x(unsigned long vaddr);
 #define find_vmemmap()		stub_false()
 #define get_phys_base()		stub_true()
 #define get_machdep_info()	get_machdep_info_s390x()
 #define get_versiondep_info()	stub_true()
-#define get_kaslr_offset(X)	stub_false()
+#define get_kaslr_offset(X)	get_kaslr_offset_s390x(X)
 #define vaddr_to_paddr(X)	vaddr_to_paddr_s390x(X)
 #define paddr_to_vaddr(X)	paddr_to_vaddr_general(X)
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
makedumpfile.h +0 -1
 #define is_phys_addr(X)		is_iomem_phys_addr_s390x(X)
--

2.17.1

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#6 lore raw

Hi, Kazu and Mikhail,

Quoted 49 lines

Hi Mikhail,

Quoted 47 lines

-----Original Message-----
Hi,

Quoted 42 lines · Kazuhito Hagio

Hi Mikhail,

Quoted 18 lines

-----Original Message-----
Hello Kazu,

I think we can try to generalize the kaslr offset extraction.
I won't speak for other architectures, but for s390 that get_kaslr_offset_arm64() should work fine. The only concern of mine is this TODO statement:

if (_text <= vaddr && vaddr <= _end) {
	DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
	return info->kaslr_offset;
	} else {
	/*
	* TODO: we need to check if it is vmalloc/vmmemmap/module
	* address, we will have different offset
	*/
	return 0;
}
Quoted 1 line

Could you explain this one?

Probably it was considered that the check would be needed to support the whole KASLR behavior when get_kaslr_offset_x86_64() was written originally.

But in the current makedumpfile for x86_64 and arm64 supporting KASLR, the offset we need is the one for symbol addresses in vmlinux only. As I said below, module symbol addresses are retrieved from vmcore. Other addresses should not be passed to the function for now, as far as I know.

So I think the TODO comment is confusing, and it would be better to remove it or change it to something like:
/*
* Returns 0 if vaddr does not need the offset to be added,
* e.g. for module address.
*/

But if s390 uses get_kaslr_offset() in its arch-specific code to adjust addresses other than kernel text address, we might need to modify it for s390, not generalize it.

Quoted 7 lines
Quoted 2 lines

Currently, s390 doesn't use get_kaslr_offset() in its arch-specific code.

OK, I pushed a patch that generalizes it to my test repository. Could you enable s390 to use it and test?
https://github.com/k-hagio/makedumpfile/tree/add-get_kaslr_offset_general

I enabled it on s390 as below and tested, it worked.

@@ -1075,7 +1075,7 @@ int is_iomem_phys_addr_s390x(unsigned long addr);
#define get_phys_base() stub_true()

 #define get_machdep_info()     get_machdep_info_s390x()
 #define get_versiondep_info()  stub_true()
-#define get_kaslr_offset(X)    stub_false()
+#define get_kaslr_offset(X)    get_kaslr_offset_general(X)
 #define vaddr_to_paddr(X)      vaddr_to_paddr_s390x(X)

But, there is still a problem that needs to be improved. In the find_kaslr_offsets(), the value of SYMBOL(_stext) is always 0(zero) and it is passed to the get_kaslr_offset(). For the following code in the get_kaslr_offset_general(), it does not work as expected.
...

	if (_text <= vaddr && vaddr <= _end)
		return info->kaslr_offset;
	else
		return 0;

...
Here is my log:
get_kaslr_offset_general: info->kaslr_offset: 67ebc000, _text:100000, _end:10ba000, vaddr:0

After applied the following patch, got the expected result.
int
find_kaslr_offsets()
{
@@ -3973,6 +4042,11 @@ find_kaslr_offsets()
* called this function between open_vmcoreinfo() and
* close_vmcoreinfo()
*/
+ READ_SYMBOL("_stext", _stext);
+ if (SYMBOL(_stext) == NOT_FOUND_SYMBOL) {
+ ERRMSG("Can't get the symbol of _stext.\n");
+ goto out;
+ }

        get_kaslr_offset(SYMBOL(_stext));

Here is my log:
get_kaslr_offset_general: info->kaslr_offset: 67ebc000, _text:100000, _end:10ba000, vaddr:67fbc000

Basically, before using the value of SYMBOL(_stext), need to ensure that the SYMBOL(_stext) is parsed correctly.

Thanks.

Quoted 118 lines

Thanks,
Kazu

Quoted 104 lines
Quoted 104 lines

Thanks,
Kazu

Quoted 99 lines

Thanks,
Mikhail

Quoted 11 lines · Kazuhito Hagio

Hi Mikhail,

Sorry for late reply.

Quoted 6 lines

-----Original Message-----
Since kernel v5.2 KASLR is supported on s390. In makedumpfile however no support has been added yet. This patch adds the arch specific function get_kaslr_offset() for s390x.
Since the values in vmcoreinfo are already relocated, the patch is mainly relevant for vmlinux processing (-x option).

Quoted 4 lines

In the current implementation of makedumpfile, the get_kaslr_offset(vaddr) is supposed to return the KASLR offset only when the offset is needed to add to the vaddr. So generally symbols from kernel (vmlinux) need it, but symbols from modules are resolved dynamically and don't need the offset.

\>

Quoted 78 lines

This patch always returns the offset if any, as a result, I guess this patch will not work as expected with module symbols in filter config file.

So... How about making get_kaslr_offset_arm64() general for other archs (get_kaslr_offset_general() or something), then using it also for s390? If OK, I can do that generalization.

Thanks,
Kazu

Quoted 68 lines
---
 arch/s390x.c   | 32 ++++++++++++++++++++++++++++++++
 makedumpfile.h |  3 ++-
 2 files changed, 34 insertions(+), 1 deletion(-)
arch/s390x.c +32 -0
index bf9d58e..892df14 100644
@@ -122,6 +122,38 @@ get_machdep_info_s390x(void)
 	return TRUE;
 }
 
+unsigned long
+get_kaslr_offset_s390x(unsigned long vaddr)
+{
+	unsigned int i;
+	char buf[BUFSIZE_FGETS], *endp;
+
+	if (!info->file_vmcoreinfo)
+		return FALSE;
+
+	if (fseek(info->file_vmcoreinfo, 0, SEEK_SET) < 0) {
+		ERRMSG("Can't seek the vmcoreinfo file(%s). %s\n",
+		       info->name_vmcoreinfo, strerror(errno));
+		return FALSE;
+	}
+
+	while (fgets(buf, BUFSIZE_FGETS, info->file_vmcoreinfo)) {
+		i = strlen(buf);
+		if (!i)
+			break;
+		if (buf[i - 1] == '\n')
+			buf[i - 1] = '\0';
+		if (strncmp(buf, STR_KERNELOFFSET,
+			    strlen(STR_KERNELOFFSET)) == 0) {
+			info->kaslr_offset =
+				strtoul(buf + strlen(STR_KERNELOFFSET), &endp, 16);
+			DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
+		}
+	}
+
+	return info->kaslr_offset;
+}
+
 static int
 is_vmalloc_addr_s390x(unsigned long vaddr)
 {
makedumpfile.h +2 -1
index ac11e90..26f6247 100644
@@ -1071,11 +1071,12 @@ unsigned long long vaddr_to_paddr_ppc(unsigned long vaddr);
 int get_machdep_info_s390x(void);
 unsigned long long vaddr_to_paddr_s390x(unsigned long vaddr);
 int is_iomem_phys_addr_s390x(unsigned long addr);
+unsigned long get_kaslr_offset_s390x(unsigned long vaddr);
 #define find_vmemmap()		stub_false()
 #define get_phys_base()		stub_true()
 #define get_machdep_info()	get_machdep_info_s390x()
 #define get_versiondep_info()	stub_true()
-#define get_kaslr_offset(X)	stub_false()
+#define get_kaslr_offset(X)	get_kaslr_offset_s390x(X)
 #define vaddr_to_paddr(X)	vaddr_to_paddr_s390x(X)
 #define paddr_to_vaddr(X)	paddr_to_vaddr_general(X)
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
makedumpfile.h +0 -1
 #define is_phys_addr(X)		is_iomem_phys_addr_s390x(X)
--

2.17.1

Quoted 5 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#7 lore raw
Quoted 73 lines · lijiang

Hi, Kazu and Mikhail,

Quoted 49 lines

Hi Mikhail,

Quoted 47 lines

-----Original Message-----
Hi,

Quoted 42 lines · Kazuhito Hagio

Hi Mikhail,

Quoted 18 lines

-----Original Message-----
Hello Kazu,

I think we can try to generalize the kaslr offset extraction.
I won't speak for other architectures, but for s390 that get_kaslr_offset_arm64() should work fine. The only concern of mine is this TODO statement:

if (_text <= vaddr && vaddr <= _end) {
	DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
	return info->kaslr_offset;
	} else {
	/*
	* TODO: we need to check if it is vmalloc/vmmemmap/module
	* address, we will have different offset
	*/
	return 0;
}
Quoted 1 line

Could you explain this one?

Probably it was considered that the check would be needed to support the whole KASLR behavior when get_kaslr_offset_x86_64() was written originally.

But in the current makedumpfile for x86_64 and arm64 supporting KASLR, the offset we need is the one for symbol addresses in vmlinux only. As I said below, module symbol addresses are retrieved from vmcore. Other addresses should not be passed to the function for now, as far as I know.

So I think the TODO comment is confusing, and it would be better to remove it or change it to something like:
/*
* Returns 0 if vaddr does not need the offset to be added,
* e.g. for module address.
*/

But if s390 uses get_kaslr_offset() in its arch-specific code to adjust addresses other than kernel text address, we might need to modify it for s390, not generalize it.

Quoted 7 lines
Quoted 2 lines

Currently, s390 doesn't use get_kaslr_offset() in its arch-specific code.

OK, I pushed a patch that generalizes it to my test repository. Could you enable s390 to use it and test?
https://github.com/k-hagio/makedumpfile/tree/add-get_kaslr_offset_general

I enabled it on s390 as below and tested, it worked.

(quoted diff) +1 -1
@@ -1075,7 +1075,7 @@ int is_iomem_phys_addr_s390x(unsigned long addr);
 #define get_phys_base()                stub_true()
 #define get_machdep_info()     get_machdep_info_s390x()
 #define get_versiondep_info()  stub_true()
-#define get_kaslr_offset(X)    stub_false()
+#define get_kaslr_offset(X)    get_kaslr_offset_general(X)
 #define vaddr_to_paddr(X)      vaddr_to_paddr_s390x(X)
 
 But, there is still a problem that needs to be improved. In the find_kaslr_offsets(),

the value of SYMBOL(_stext) is always 0(zero) and it is passed to the get_kaslr_offset(). For the following code in the get_kaslr_offset_general(), it does not work as expected.
...

Quoted 4 lines
	if (_text <= vaddr && vaddr <= _end)
		return info->kaslr_offset;
	else
		return 0;

In addition, the above code confused me, it will always return 0 on s390(please refer to my logs).

Thanks.

Quoted 152 lines

...
Here is my log:
get_kaslr_offset_general: info->kaslr_offset: 67ebc000, _text:100000, _end:10ba000, vaddr:0

After applied the following patch, got the expected result.
int
find_kaslr_offsets()
{

(quoted diff) +5 -0
@@ -3973,6 +4042,11 @@ find_kaslr_offsets()
         * called this function between open_vmcoreinfo() and
         * close_vmcoreinfo()
         */
+       READ_SYMBOL("_stext", _stext);
+       if (SYMBOL(_stext) == NOT_FOUND_SYMBOL) {
+                ERRMSG("Can't get the symbol of _stext.\n");
+                goto out;
+       }
        get_kaslr_offset(SYMBOL(_stext));
 

Here is my log:
get_kaslr_offset_general: info->kaslr_offset: 67ebc000, _text:100000, _end:10ba000, vaddr:67fbc000

Basically, before using the value of SYMBOL(_stext), need to ensure that the SYMBOL(_stext) is parsed correctly.

Thanks.

Quoted 118 lines

Thanks,
Kazu

Quoted 104 lines
Quoted 104 lines

Thanks,
Kazu

Quoted 99 lines

Thanks,
Mikhail

Quoted 11 lines · Kazuhito Hagio

Hi Mikhail,

Sorry for late reply.

Quoted 6 lines

-----Original Message-----
Since kernel v5.2 KASLR is supported on s390. In makedumpfile however no support has been added yet. This patch adds the arch specific function get_kaslr_offset() for s390x.
Since the values in vmcoreinfo are already relocated, the patch is mainly relevant for vmlinux processing (-x option).

Quoted 4 lines

In the current implementation of makedumpfile, the get_kaslr_offset(vaddr) is supposed to return the KASLR offset only when the offset is needed to add to the vaddr. So generally symbols from kernel (vmlinux) need it, but symbols from modules are resolved dynamically and don't need the offset.

\>

Quoted 78 lines

This patch always returns the offset if any, as a result, I guess this patch will not work as expected with module symbols in filter config file.

So... How about making get_kaslr_offset_arm64() general for other archs (get_kaslr_offset_general() or something), then using it also for s390? If OK, I can do that generalization.

Thanks,
Kazu

Quoted 68 lines
---
 arch/s390x.c   | 32 ++++++++++++++++++++++++++++++++
 makedumpfile.h |  3 ++-
 2 files changed, 34 insertions(+), 1 deletion(-)
arch/s390x.c +32 -0
index bf9d58e..892df14 100644
@@ -122,6 +122,38 @@ get_machdep_info_s390x(void)
 	return TRUE;
 }
 
+unsigned long
+get_kaslr_offset_s390x(unsigned long vaddr)
+{
+	unsigned int i;
+	char buf[BUFSIZE_FGETS], *endp;
+
+	if (!info->file_vmcoreinfo)
+		return FALSE;
+
+	if (fseek(info->file_vmcoreinfo, 0, SEEK_SET) < 0) {
+		ERRMSG("Can't seek the vmcoreinfo file(%s). %s\n",
+		       info->name_vmcoreinfo, strerror(errno));
+		return FALSE;
+	}
+
+	while (fgets(buf, BUFSIZE_FGETS, info->file_vmcoreinfo)) {
+		i = strlen(buf);
+		if (!i)
+			break;
+		if (buf[i - 1] == '\n')
+			buf[i - 1] = '\0';
+		if (strncmp(buf, STR_KERNELOFFSET,
+			    strlen(STR_KERNELOFFSET)) == 0) {
+			info->kaslr_offset =
+				strtoul(buf + strlen(STR_KERNELOFFSET), &endp, 16);
+			DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
+		}
+	}
+
+	return info->kaslr_offset;
+}
+
 static int
 is_vmalloc_addr_s390x(unsigned long vaddr)
 {
makedumpfile.h +2 -1
index ac11e90..26f6247 100644
@@ -1071,11 +1071,12 @@ unsigned long long vaddr_to_paddr_ppc(unsigned long vaddr);
 int get_machdep_info_s390x(void);
 unsigned long long vaddr_to_paddr_s390x(unsigned long vaddr);
 int is_iomem_phys_addr_s390x(unsigned long addr);
+unsigned long get_kaslr_offset_s390x(unsigned long vaddr);
 #define find_vmemmap()		stub_false()
 #define get_phys_base()		stub_true()
 #define get_machdep_info()	get_machdep_info_s390x()
 #define get_versiondep_info()	stub_true()
-#define get_kaslr_offset(X)	stub_false()
+#define get_kaslr_offset(X)	get_kaslr_offset_s390x(X)
 #define vaddr_to_paddr(X)	vaddr_to_paddr_s390x(X)
 #define paddr_to_vaddr(X)	paddr_to_vaddr_general(X)
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
makedumpfile.h +0 -1
 #define is_phys_addr(X)		is_iomem_phys_addr_s390x(X)
--

2.17.1

Quoted 5 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Quoted 5 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#8 lore raw

Hi Lianbo,

Quoted 62 lines

-----Original Message-----

Quoted 60 lines · lijiang

Hi, Kazu and Mikhail,

Quoted 49 lines

Hi Mikhail,

Quoted 47 lines

-----Original Message-----
Hi,

Quoted 42 lines · Kazuhito Hagio

Hi Mikhail,

Quoted 18 lines

-----Original Message-----
Hello Kazu,

I think we can try to generalize the kaslr offset extraction.
I won't speak for other architectures, but for s390 that get_kaslr_offset_arm64() should work fine. The only concern of mine is this TODO statement:

if (_text <= vaddr && vaddr <= _end) {
	DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
	return info->kaslr_offset;
	} else {
	/*
	* TODO: we need to check if it is vmalloc/vmmemmap/module
	* address, we will have different offset
	*/
	return 0;
}
Quoted 1 line

Could you explain this one?

Probably it was considered that the check would be needed to support the whole KASLR behavior when get_kaslr_offset_x86_64() was written originally.

But in the current makedumpfile for x86_64 and arm64 supporting KASLR, the offset we need is the one for symbol addresses in vmlinux only. As I said below, module symbol addresses are retrieved from vmcore. Other addresses should not be passed to the function for now, as far as I know.

So I think the TODO comment is confusing, and it would be better to remove it or change it to something like:
/*
* Returns 0 if vaddr does not need the offset to be added,
* e.g. for module address.
*/

But if s390 uses get_kaslr_offset() in its arch-specific code to adjust addresses other than kernel text address, we might need to modify it for s390, not generalize it.

Quoted 7 lines
Quoted 2 lines

Currently, s390 doesn't use get_kaslr_offset() in its arch-specific code.

OK, I pushed a patch that generalizes it to my test repository. Could you enable s390 to use it and test?
https://github.com/k-hagio/makedumpfile/tree/add-get_kaslr_offset_general

I enabled it on s390 as below and tested, it worked.

Thank you for testing.

Quoted 9 lines
Quoted 9 lines
(quoted diff) +1 -1
@@ -1075,7 +1075,7 @@ int is_iomem_phys_addr_s390x(unsigned long addr);
 #define get_phys_base()                stub_true()
 #define get_machdep_info()     get_machdep_info_s390x()
 #define get_versiondep_info()  stub_true()
-#define get_kaslr_offset(X)    stub_false()
+#define get_kaslr_offset(X)    get_kaslr_offset_general(X)
 #define vaddr_to_paddr(X)      vaddr_to_paddr_s390x(X)
 
Quoted 8 lines
Quoted 8 lines
(quoted diff) +0 -0
 But, there is still a problem that needs to be improved. In the find_kaslr_offsets(),

the value of SYMBOL(_stext) is always 0(zero) and it is passed to the get_kaslr_offset(). For the following code in the get_kaslr_offset_general(), it does not work as expected.
...

	if (_text <= vaddr && vaddr <= _end)
		return info->kaslr_offset;
	else
		return 0;

I don't know why the SYMBOL(_stext) is passed to the get_kaslr_offset() there, but since the return value of get_kaslr_offset() is not used in the find_kaslr_offsets(), it's meaningless and not harmful. So it is not worth doing READ_SYMBOL(_stext) there for now.

Quoted 2 lines

In addition, the above code confused me, it will always return 0 on s390(please refer to my logs).

The aim of get_kaslr_offset() here is only setting info->kaslr_offset to the value from vmcoreinfo for the SYMBOL_INIT() macro.
(get_kaslr_offset() returns the kaslr offset in the resolve_config_entry().)

But yeah, the get_kaslr_offset(SYMBOL(_stext)) is confusing and not good. Passing 0 might be a bit better..?

Thanks,
Kazu

Quoted 161 lines

Thanks.

Quoted 157 lines

...
Here is my log:
get_kaslr_offset_general: info->kaslr_offset: 67ebc000, _text:100000, _end:10ba000, vaddr:0

After applied the following patch, got the expected result.
int
find_kaslr_offsets()
{

(quoted diff) +5 -0
@@ -3973,6 +4042,11 @@ find_kaslr_offsets()
         * called this function between open_vmcoreinfo() and
         * close_vmcoreinfo()
         */
+       READ_SYMBOL("_stext", _stext);
+       if (SYMBOL(_stext) == NOT_FOUND_SYMBOL) {
+                ERRMSG("Can't get the symbol of _stext.\n");
+                goto out;
+       }
        get_kaslr_offset(SYMBOL(_stext));
 

Here is my log:
get_kaslr_offset_general: info->kaslr_offset: 67ebc000, _text:100000, _end:10ba000, vaddr:67fbc000

Basically, before using the value of SYMBOL(_stext), need to ensure that the SYMBOL(_stext) is parsed correctly.

Thanks.

Quoted 118 lines

Thanks,
Kazu

Quoted 104 lines
Quoted 104 lines

Thanks,
Kazu

Quoted 99 lines

Thanks,
Mikhail

Quoted 11 lines · Kazuhito Hagio

Hi Mikhail,

Sorry for late reply.

Quoted 6 lines

-----Original Message-----
Since kernel v5.2 KASLR is supported on s390. In makedumpfile however no support has been added yet. This patch adds the arch specific function get_kaslr_offset() for s390x.
Since the values in vmcoreinfo are already relocated, the patch is mainly relevant for vmlinux processing (-x option).

Quoted 4 lines

In the current implementation of makedumpfile, the get_kaslr_offset(vaddr) is supposed to return the KASLR offset only when the offset is needed to add to the vaddr. So generally symbols from kernel (vmlinux) need it, but symbols from modules are resolved dynamically and don't need the offset.

\>

Quoted 78 lines

This patch always returns the offset if any, as a result, I guess this patch will not work as expected with module symbols in filter config file.

So... How about making get_kaslr_offset_arm64() general for other archs (get_kaslr_offset_general() or something), then using it also for s390? If OK, I can do that generalization.

Thanks,
Kazu

Quoted 68 lines
---
 arch/s390x.c   | 32 ++++++++++++++++++++++++++++++++
 makedumpfile.h |  3 ++-
 2 files changed, 34 insertions(+), 1 deletion(-)
arch/s390x.c +32 -0
index bf9d58e..892df14 100644
@@ -122,6 +122,38 @@ get_machdep_info_s390x(void)
 	return TRUE;
 }
 
+unsigned long
+get_kaslr_offset_s390x(unsigned long vaddr)
+{
+	unsigned int i;
+	char buf[BUFSIZE_FGETS], *endp;
+
+	if (!info->file_vmcoreinfo)
+		return FALSE;
+
+	if (fseek(info->file_vmcoreinfo, 0, SEEK_SET) < 0) {
+		ERRMSG("Can't seek the vmcoreinfo file(%s). %s\n",
+		       info->name_vmcoreinfo, strerror(errno));
+		return FALSE;
+	}
+
+	while (fgets(buf, BUFSIZE_FGETS, info->file_vmcoreinfo)) {
+		i = strlen(buf);
+		if (!i)
+			break;
+		if (buf[i - 1] == '\n')
+			buf[i - 1] = '\0';
+		if (strncmp(buf, STR_KERNELOFFSET,
+			    strlen(STR_KERNELOFFSET)) == 0) {
+			info->kaslr_offset =
+				strtoul(buf + strlen(STR_KERNELOFFSET), &endp, 16);
+			DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
+		}
+	}
+
+	return info->kaslr_offset;
+}
+
 static int
 is_vmalloc_addr_s390x(unsigned long vaddr)
 {
makedumpfile.h +2 -1
index ac11e90..26f6247 100644
@@ -1071,11 +1071,12 @@ unsigned long long vaddr_to_paddr_ppc(unsigned long vaddr);
 int get_machdep_info_s390x(void);
 unsigned long long vaddr_to_paddr_s390x(unsigned long vaddr);
 int is_iomem_phys_addr_s390x(unsigned long addr);
+unsigned long get_kaslr_offset_s390x(unsigned long vaddr);
 #define find_vmemmap()		stub_false()
 #define get_phys_base()		stub_true()
 #define get_machdep_info()	get_machdep_info_s390x()
 #define get_versiondep_info()	stub_true()
-#define get_kaslr_offset(X)	stub_false()
+#define get_kaslr_offset(X)	get_kaslr_offset_s390x(X)
 #define vaddr_to_paddr(X)	vaddr_to_paddr_s390x(X)
 #define paddr_to_vaddr(X)	paddr_to_vaddr_general(X)
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
makedumpfile.h +0 -1
 #define is_phys_addr(X)		is_iomem_phys_addr_s390x(X)
--

2.17.1

Quoted 5 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#9 lore raw
Quoted 58 lines

Hi Lianbo,

Quoted 56 lines

-----Original Message-----

Quoted 54 lines · lijiang

Hi, Kazu and Mikhail,

Quoted 52 lines

Hi Mikhail,

Quoted 49 lines

-----Original Message-----
Hi,

Quoted 39 lines · Kazuhito Hagio

Hi Mikhail,

Quoted 18 lines

-----Original Message-----
Hello Kazu,

I think we can try to generalize the kaslr offset extraction.
I won't speak for other architectures, but for s390 that get_kaslr_offset_arm64() should work fine. The only concern of mine is this TODO statement:

if (_text <= vaddr && vaddr <= _end) {
	DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
	return info->kaslr_offset;
	} else {
	/*
	* TODO: we need to check if it is vmalloc/vmmemmap/module
	* address, we will have different offset
	*/
	return 0;
}
Quoted 1 line

Could you explain this one?

Probably it was considered that the check would be needed to support the whole KASLR behavior when get_kaslr_offset_x86_64() was written originally.

But in the current makedumpfile for x86_64 and arm64 supporting KASLR, the offset we need is the one for symbol addresses in vmlinux only. As I said below, module symbol addresses are retrieved from vmcore. Other addresses should not be passed to the function for now, as far as I know.

So I think the TODO comment is confusing, and it would be better to remove it or change it to something like:
/*
* Returns 0 if vaddr does not need the offset to be added,
* e.g. for module address.
*/

Quoted 3 lines

But if s390 uses get_kaslr_offset() in its arch-specific code to adjust addresses other than kernel text address, we might need to modify it for s390, not generalize it.

Currently, s390 doesn't use get_kaslr_offset() in its arch-specific code.

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

OK, I pushed a patch that generalizes it to my test repository. Could you enable s390 to use it and test?
https://github.com/k-hagio/makedumpfile/tree/add-get_kaslr_offset_general

I enabled it on s390 as below and tested, it worked.

Thank you for testing.

It's my pleasure.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
(quoted diff) +1 -1
@@ -1075,7 +1075,7 @@ int is_iomem_phys_addr_s390x(unsigned long addr);
 #define get_phys_base()                stub_true()
 #define get_machdep_info()     get_machdep_info_s390x()
 #define get_versiondep_info()  stub_true()
-#define get_kaslr_offset(X)    stub_false()
+#define get_kaslr_offset(X)    get_kaslr_offset_general(X)
 #define vaddr_to_paddr(X)      vaddr_to_paddr_s390x(X)
 
Quoted 14 lines
Quoted 8 lines
Quoted 8 lines
(quoted diff) +0 -0
 But, there is still a problem that needs to be improved. In the find_kaslr_offsets(),

the value of SYMBOL(_stext) is always 0(zero) and it is passed to the get_kaslr_offset(). For the following code in the get_kaslr_offset_general(), it does not work as expected.
...

	if (_text <= vaddr && vaddr <= _end)
		return info->kaslr_offset;
	else
		return 0;

I don't know why the SYMBOL(_stext) is passed to the get_kaslr_offset() there, but since the return value of get_kaslr_offset() is not used in the find_kaslr_offsets(), it's meaningless and not harmful. So it is not worth doing READ_SYMBOL(_stext) there for now.

Sounds good.

Quoted 7 lines
Quoted 2 lines

In addition, the above code confused me, it will always return 0 on s390(please refer to my logs).

The aim of get_kaslr_offset() here is only setting info->kaslr_offset to the value from vmcoreinfo for the SYMBOL_INIT() macro.
(get_kaslr_offset() returns the kaslr offset in the resolve_config_entry().)

Thanks for your explanation, Kazu.

Quoted 3 lines

But yeah, the get_kaslr_offset(SYMBOL(_stext)) is confusing and not good. Passing 0 might be a bit better..?

Yes, looks good to me.

Lianbo

Quoted 165 lines

Thanks,
Kazu

Quoted 161 lines

Thanks.

Quoted 157 lines

...
Here is my log:
get_kaslr_offset_general: info->kaslr_offset: 67ebc000, _text:100000, _end:10ba000, vaddr:0

After applied the following patch, got the expected result.
int
find_kaslr_offsets()
{

(quoted diff) +5 -0
@@ -3973,6 +4042,11 @@ find_kaslr_offsets()
         * called this function between open_vmcoreinfo() and
         * close_vmcoreinfo()
         */
+       READ_SYMBOL("_stext", _stext);
+       if (SYMBOL(_stext) == NOT_FOUND_SYMBOL) {
+                ERRMSG("Can't get the symbol of _stext.\n");
+                goto out;
+       }
        get_kaslr_offset(SYMBOL(_stext));
 

Here is my log:
get_kaslr_offset_general: info->kaslr_offset: 67ebc000, _text:100000, _end:10ba000, vaddr:67fbc000

Basically, before using the value of SYMBOL(_stext), need to ensure that the SYMBOL(_stext) is parsed correctly.

Thanks.

Quoted 118 lines

Thanks,
Kazu

Quoted 104 lines
Quoted 104 lines

Thanks,
Kazu

Quoted 99 lines

Thanks,
Mikhail

Quoted 11 lines · Kazuhito Hagio

Hi Mikhail,

Sorry for late reply.

Quoted 6 lines

-----Original Message-----
Since kernel v5.2 KASLR is supported on s390. In makedumpfile however no support has been added yet. This patch adds the arch specific function get_kaslr_offset() for s390x.
Since the values in vmcoreinfo are already relocated, the patch is mainly relevant for vmlinux processing (-x option).

Quoted 4 lines

In the current implementation of makedumpfile, the get_kaslr_offset(vaddr) is supposed to return the KASLR offset only when the offset is needed to add to the vaddr. So generally symbols from kernel (vmlinux) need it, but symbols from modules are resolved dynamically and don't need the offset.

\>

Quoted 78 lines

This patch always returns the offset if any, as a result, I guess this patch will not work as expected with module symbols in filter config file.

So... How about making get_kaslr_offset_arm64() general for other archs (get_kaslr_offset_general() or something), then using it also for s390? If OK, I can do that generalization.

Thanks,
Kazu

Quoted 68 lines
---
 arch/s390x.c   | 32 ++++++++++++++++++++++++++++++++
 makedumpfile.h |  3 ++-
 2 files changed, 34 insertions(+), 1 deletion(-)
arch/s390x.c +32 -0
index bf9d58e..892df14 100644
@@ -122,6 +122,38 @@ get_machdep_info_s390x(void)
 	return TRUE;
 }
 
+unsigned long
+get_kaslr_offset_s390x(unsigned long vaddr)
+{
+	unsigned int i;
+	char buf[BUFSIZE_FGETS], *endp;
+
+	if (!info->file_vmcoreinfo)
+		return FALSE;
+
+	if (fseek(info->file_vmcoreinfo, 0, SEEK_SET) < 0) {
+		ERRMSG("Can't seek the vmcoreinfo file(%s). %s\n",
+		       info->name_vmcoreinfo, strerror(errno));
+		return FALSE;
+	}
+
+	while (fgets(buf, BUFSIZE_FGETS, info->file_vmcoreinfo)) {
+		i = strlen(buf);
+		if (!i)
+			break;
+		if (buf[i - 1] == '\n')
+			buf[i - 1] = '\0';
+		if (strncmp(buf, STR_KERNELOFFSET,
+			    strlen(STR_KERNELOFFSET)) == 0) {
+			info->kaslr_offset =
+				strtoul(buf + strlen(STR_KERNELOFFSET), &endp, 16);
+			DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset);
+		}
+	}
+
+	return info->kaslr_offset;
+}
+
 static int
 is_vmalloc_addr_s390x(unsigned long vaddr)
 {
makedumpfile.h +2 -1
index ac11e90..26f6247 100644
@@ -1071,11 +1071,12 @@ unsigned long long vaddr_to_paddr_ppc(unsigned long vaddr);
 int get_machdep_info_s390x(void);
 unsigned long long vaddr_to_paddr_s390x(unsigned long vaddr);
 int is_iomem_phys_addr_s390x(unsigned long addr);
+unsigned long get_kaslr_offset_s390x(unsigned long vaddr);
 #define find_vmemmap()		stub_false()
 #define get_phys_base()		stub_true()
 #define get_machdep_info()	get_machdep_info_s390x()
 #define get_versiondep_info()	stub_true()
-#define get_kaslr_offset(X)	stub_false()
+#define get_kaslr_offset(X)	get_kaslr_offset_s390x(X)
 #define vaddr_to_paddr(X)	vaddr_to_paddr_s390x(X)
 #define paddr_to_vaddr(X)	paddr_to_vaddr_general(X)
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
makedumpfile.h +0 -1
 #define is_phys_addr(X)		is_iomem_phys_addr_s390x(X)
--

2.17.1

Quoted 5 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec