This patch fixes an issue where a segfault occurring inside a CT caused
the kernel segfault message to be logged to the CT dmesg, while the
opcode dump was printed to the host dmesg. It also fixes a bug where the
segfault message recorded in the CT dmesg used the host PID instead of
the PID inside the container.

https://virtuozzo.atlassian.net/browse/VSTOR-119875
Fixes c3d2bd4b6946f ("ve: Use ve_printk() for often kernel messages about user 
actions")

Signed-off-by: Aleksei Oladko <[email protected]>
---
 arch/x86/include/asm/stacktrace.h |  1 +
 arch/x86/kernel/dumpstack.c       | 11 ++++++++---
 arch/x86/mm/fault.c               |  7 ++++---
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/stacktrace.h 
b/arch/x86/include/asm/stacktrace.h
index 3881b5333eb8..09e08f36d02e 100644
--- a/arch/x86/include/asm/stacktrace.h
+++ b/arch/x86/include/asm/stacktrace.h
@@ -109,6 +109,7 @@ struct stack_frame_ia32 {
     u32 return_address;
 };
 
+void ve_show_opcodes(struct pt_regs *regs, const char *loglvl, int dst);
 void show_opcodes(struct pt_regs *regs, const char *loglvl);
 void show_ip(struct pt_regs *regs, const char *loglvl);
 #endif /* _ASM_X86_STACKTRACE_H */
diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
index a7d562697e50..b8cd4ae49e9e 100644
--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -110,7 +110,7 @@ static int copy_code(struct pt_regs *regs, u8 *buf, 
unsigned long src,
  * Thus, the 2/3rds prologue and 64 byte OPCODE_BUFSIZE is just a random
  * guesstimate in attempt to achieve all of the above.
  */
-void show_opcodes(struct pt_regs *regs, const char *loglvl)
+void ve_show_opcodes(struct pt_regs *regs, const char *loglvl, int dst)
 {
 #define PROLOGUE_SIZE 42
 #define EPILOGUE_SIZE 21
@@ -120,7 +120,7 @@ void show_opcodes(struct pt_regs *regs, const char *loglvl)
 
        switch (copy_code(regs, opcodes, prologue, sizeof(opcodes))) {
        case 0:
-               printk("%sCode: %" __stringify(PROLOGUE_SIZE) "ph <%02x> %"
+               ve_printk(dst, "%sCode: %" __stringify(PROLOGUE_SIZE) "ph 
<%02x> %"
                       __stringify(EPILOGUE_SIZE) "ph\n", loglvl, opcodes,
                       opcodes[PROLOGUE_SIZE], opcodes + PROLOGUE_SIZE + 1);
                break;
@@ -128,12 +128,17 @@ void show_opcodes(struct pt_regs *regs, const char 
*loglvl)
                /* No access to the user space stack of other tasks. Ignore. */
                break;
        default:
-               printk("%sCode: Unable to access opcode bytes at 0x%lx.\n",
+               ve_printk(dst, "%sCode: Unable to access opcode bytes at 
0x%lx.\n",
                       loglvl, prologue);
                break;
        }
 }
 
+void show_opcodes(struct pt_regs *regs, const char *loglvl)
+{
+       return ve_show_opcodes(regs, loglvl, VE0_LOG);
+}
+
 void show_ip(struct pt_regs *regs, const char *loglvl)
 {
 #ifdef CONFIG_X86_32
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index 2beac0d7924d..ca65e80dacab 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -757,8 +757,9 @@ show_signal_msg(struct pt_regs *regs, unsigned long 
error_code,
                return;
 
        ve_printk(VE_LOG, "%s%s[%d]: segfault at %lx ip %px sp %px error %lx",
-               loglvl, tsk->comm, task_pid_nr(tsk), address,
-               (void *)regs->ip, (void *)regs->sp, error_code);
+               loglvl, tsk->comm,
+               ve_is_super(get_exec_env()) ? task_pid_nr(tsk) : 
task_pid_vnr(tsk),
+               address, (void *)regs->ip, (void *)regs->sp, error_code);
 
        ve_print_vma_addr(VE_LOG, KERN_CONT " in ", regs->ip);
 
@@ -773,7 +774,7 @@ show_signal_msg(struct pt_regs *regs, unsigned long 
error_code,
 
        ve_printk(VE_LOG, KERN_CONT "\n");
 
-       show_opcodes(regs, loglvl);
+       ve_show_opcodes(regs, loglvl, VE_LOG);
 }
 
 static void
-- 
2.43.0

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to