简体   繁体   English

一个进程可以覆盖另一个进程的内存吗?

[英]Can one process overwrite the memory of another process?

My project is composed of 3 processes. 我的项目由3个流程组成。 Process 1 is a "server" of process 2 and 3 and implements shared memory. 进程1是进程2和3的“服务器”,并实现共享内存。 Process 2 randomly crashes with application errors, trying to access it's own memory, that has been corrupted somehow. 进程2随应用程序错误随机崩溃,试图访问它自己的内存,已经以某种方式损坏。

Error is: Invalid instruction at some address at memory location some not good address. 错误是:内存位置某些地址的指令无效,有些地址不好。

Where would I start looking and what type of things would I look for in process 1, to see if it is overwriting process 2's memory? 我将在哪里开始查看以及在过程1中我将查找哪些类型的内容,以查看它是否覆盖了进程2的内存?

Thank You. 谢谢。

Accidentally overwrite the memory of another process (without its cooperation)? 无意中覆盖了另一个进程的内存(没有它的合作)? No*, because you have to "accidentally" do a lot of things correctly. 不*,因为你必须“意外”正确地做很多事情。 (You have to "accidentally" open a handle to the process, and also "accidentally" call WriteProcessMemory .) (您必须“意外”打开进程的句柄,并“意外”调用WriteProcessMemory 。)

Intentionally? 故意地? Yes, using the WriteProcessMemory function. 是的,使用WriteProcessMemory函数。

* If you're sharing memory, the likelihood of an error skyrockets. *如果您正在共享内存,则出现错误的可能性会急剧上升。

A process can only overwrite another process' memory if it actively tries to. 如果进程主动尝试,则进程只能覆盖另一个进程的内存。 Debugging is one example, shared memory is another. 调试就是一个例子,共享内存是另一个例子。 Accidental writing to either code or data area of another process is very unlikely. 意外写入另一个进程的代码或数据区域是不太可能的。

So the problem is, most likely, a bug withing process 2. I mean, process 2 is not even sharing its memory, right? 所以问题是,最有可能的是,进程2的错误。我的意思是,进程2甚至不共享其内存,对吧? So process 1 cannot possibly overwrite it. 因此,进程1不可能覆盖它。

The OS will prevent a process from overwriting another process's memory, unless you are running as part of the kernel. 除非您作为内核的一部分运行,否则操作系统将阻止进程覆盖其他进程的内存。 Use a memory debugger like valgrind to track down the cause of any memory access errors. 使用像valgrind这样的内存调试器来跟踪任何内存访问错误的原因。

Edit: you can also include the possibility of using OS calls to access another process's memory, but as everyone has said, you most likely aren't doing that. 编辑:你还可以包括使用操作系统调用来访问另一个进程的内存的可能性,但正如大家所说,你很可能没有这样做。 Passing pointers in the shared memory is the most likely error here, but I still suggest using a tool like valgrind. 在共享内存中传递指针是最可能的错误,但我仍然建议使用像valgrind这样的工具。

Do the data structures in the shared memory include any absolute pointers? 共享内存中的数据结构是否包含任何绝对指针? Not only is this a bad idea, because absolute pointers aren't meaningful in other processes, but one process could convince the other process to write wildly through its memory. 这不仅是一个坏主意,因为绝对指针在其他进程中没有意义,但是一个进程可以说服其他进程通过其内存进行疯狂编写。

In general, the memory management unit prevents any process from directly overwriting/corrupting another process's memory. 通常,内存管理单元可以防止任何进程直接覆盖/破坏其他进程的内存。 Shared memory (including file mappings) and the WriteProcessMemory function are exceptions to the general rule. 共享内存(包括文件映射)和WriteProcessMemory函数是一般规则的例外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM