Kernel Newbies archive on lore.kernel.org
 help / color / Atom feed
From: Aruna Hewapathirane <aruna.hewapathirane@gmail.com>
To: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn>
Cc: kernelnewbies <kernelnewbies@kernelnewbies.org>
Subject: Re: how to determine whether the source code is same between two kernels
Date: Fri, 10 May 2019 22:11:31 -0400
Message-ID: <CAFSeFg9k6vkppSzRoO4viaGogC9f+89pcAsaboOaRAq5QN9V7A@mail.gmail.com> (raw)
In-Reply-To: <5de6f762.7230c.16a96a52517.Coremail.wuzhouhui14@mails.ucas.ac.cn>

[-- Attachment #1.1: Type: text/plain, Size: 2291 bytes --]

On Wed, May 8, 2019 at 4:53 AM wuzhouhui <wuzhouhui14@mails.ucas.ac.cn>
wrote:
> Hi,

> Suppose I have two kernels, one is A.B.C build by people Tom. And
> the other is A.B.C build by Jerry. The source code have been deleted
> after kernel is build and installed. Now I want to know whether the
> source code of these two kernel is the same (even if they have the same
> name). All I have is binaries (e.g. vmlinux, config, *.ko, System.map).

> Is it possible?
Within sane defaults yes it is possible. Think of it this way, if the
source code is
the 'same'  we can safely assume that the kernel built by Tom will function
and behave
'exactly' the same as the kernel built by Jerry. Behavior can be traced and
analyzed.

diff, dmesg, lsmod, tree and objdump are your friends :-)

Run diff vmlinuz-Tom vmlinuz-Jerry and see if they differ. Then just  to
make
sure follow below steps:

1 - Boot kernel-Tom and  redirect dmesg output to file(s)
2 - dmesg -k > kernel-Tom.txt
3 - dmesg -u > userspace-Tom.txt
4 - lsmod > modules-Tom.txt
5 - tree / > fs-Tom.txt

Now we have what the kernel prints while booting in kernel-Tom.txt and what
userspace prints
in userspace-Tom.txt and loaded modules in modules-Tom.txt and the folder
structure under root
in fs-Tom.txt.

Now repeat the same process with kernel-Jerry

1 - Boot kernel-Jerry
2 - dmesg -k > kernel-Jerry.txt
3 - dmesg -u > userspace-Jerry.txt
4 - lsmod > modules-Jerry.txt
5 - tree / > fs-Jerry.txt

Then run diff on those files..

1 - diff kernel-Tom.txt kernel-Jerry.txt
2 - diff userspace-Tom userspace-Jerry
3 - diff modules-Tom modules-Jerry
4 - diff fs-Tom fs-Jerry

if you want to dig deeper use objdump -d vmlinuz-Tom then objdump -d
vmlinuz-Jerry
which is really overkill unless there is output from diff that says the
file(s) differ.

If you really really need the source there are decompilers :
IDA <https://www.hex-rays.com/products/ida/>
ghidra <https://ghidra-sre.org/>
snowman <https://derevenets.com/>
hopper <https://www.hopperapp.com/>

Keep in mind what Valdis pointed out that though the source may be exactly
the same,
depending on what compiler flags were used the binaries may differ.

You had asked..
> Is it possible?
Simple answer: In the Linux world the impossible becomes very possible :)

Good luck - Aruna

[-- Attachment #1.2: Type: text/html, Size: 4487 bytes --]

<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, May 8, 2019 at 4:53 AM wuzhouhui &lt;<a href="mailto:wuzhouhui14@mails.ucas.ac.cn">wuzhouhui14@mails.ucas.ac.cn</a>&gt; wrote:</div><div dir="ltr" class="gmail_attr">&gt; Hi,</div><div><br></div><div>&gt; Suppose I have two kernels, one is A.B.C build by people Tom. And</div><div>&gt; the other is A.B.C build by Jerry. The source code have been deleted</div><div>&gt; after kernel is build and installed. Now I want to know whether the</div><div>&gt; source code of these two kernel is the same (even if they have the same</div><div>&gt; name). All I have is binaries (e.g. vmlinux, config, *.ko, System.map).</div><div><br></div><div>&gt; Is it possible?</div>Within sane defaults yes it is possible. Think of it this way, if the source code is <br></div><div class="gmail_quote">the &#39;same&#39;  we can safely assume that the kernel built by Tom will function and behave <br></div><div class="gmail_quote">&#39;exactly&#39; the same as the kernel built by Jerry. Behavior can be traced and analyzed.<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">diff, dmesg, lsmod, tree and objdump are your friends :-)</div><div class="gmail_quote"><br></div><div class="gmail_quote">Run diff vmlinuz-Tom vmlinuz-Jerry and see if they differ. Then just  to make</div><div class="gmail_quote">sure follow below steps:<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">1 - Boot kernel-Tom and  redirect dmesg output to file(s)</div><div class="gmail_quote">2 - dmesg -k &gt; kernel-Tom.txt    <br></div><div class="gmail_quote">3 - dmesg -u &gt; userspace-Tom.txt</div><div class="gmail_quote">4 - lsmod &gt; modules-Tom.txt</div><div class="gmail_quote">5 - tree / &gt; fs-Tom.txt</div><div class="gmail_quote"><br></div><div class="gmail_quote">Now we have what the kernel prints while booting in kernel-Tom.txt and what userspace prints <br></div><div class="gmail_quote">in userspace-Tom.txt and loaded modules in modules-Tom.txt and the folder structure under root</div><div class="gmail_quote">in fs-Tom.txt.</div><div class="gmail_quote"><br></div><div class="gmail_quote">Now repeat the same process with kernel-Jerry<br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><div class="gmail_quote">1 - Boot kernel-Jerry</div><div class="gmail_quote">2 - dmesg -k &gt; kernel-Jerry.txt</div><div class="gmail_quote">3 - dmesg -u &gt; userspace-Jerry.txt</div><div class="gmail_quote">4 - lsmod &gt; modules-Jerry.txt</div><div class="gmail_quote">5 - tree / &gt; fs-Jerry.txt</div><div class="gmail_quote"><br></div><div class="gmail_quote">Then run diff on those files..<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">1 - diff kernel-Tom.txt kernel-Jerry.txt   <br></div><div class="gmail_quote">2 - diff userspace-Tom userspace-Jerry</div><div class="gmail_quote">3 - diff modules-Tom modules-Jerry</div><div class="gmail_quote">4 - diff fs-Tom fs-Jerry<br></div><div class="gmail_quote"><br></div></div><div class="gmail_quote">if you want to dig deeper use objdump -d vmlinuz-Tom then objdump -d vmlinuz-Jerry</div><div class="gmail_quote">which is really overkill unless there is output from diff that says the file(s) differ.<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">If you really really need the source there are decompilers :</div><div class="gmail_quote"><a href="https://www.hex-rays.com/products/ida/">IDA</a></div><div class="gmail_quote"><a href="https://ghidra-sre.org/">ghidra</a></div><div class="gmail_quote"><a href="https://derevenets.com/">snowman</a></div><div class="gmail_quote"><a href="https://www.hopperapp.com/">hopper</a><br></div><div class="gmail_quote"><br></div><div class="gmail_quote">Keep in mind what Valdis pointed out that though the source may be exactly the same,</div><div class="gmail_quote">depending on what compiler flags were used the binaries may differ. <br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><div>You had asked..</div><div>&gt; Is it possible?</div><div>Simple answer: In the Linux world the impossible becomes very possible :)</div><div><br></div><div>Good luck - Aruna<br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div></div>

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  parent reply index

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-08  8:52 wuzhouhui
2019-05-08  9:25 ` Greg KH
2019-05-08  9:43   ` wuzhouhui
2019-05-08 10:08     ` greg kh
2019-05-08 13:43 ` Valdis Klētnieks
2019-05-11  2:11 ` Aruna Hewapathirane [this message]
2019-05-11  3:58   ` Valdis Klētnieks
2019-05-11 13:20     ` Aruna Hewapathirane
2019-05-11 13:53       ` Valdis Klētnieks
2019-05-11 23:47         ` chiachen

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFSeFg9k6vkppSzRoO4viaGogC9f+89pcAsaboOaRAq5QN9V7A@mail.gmail.com \
    --to=aruna.hewapathirane@gmail.com \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=wuzhouhui14@mails.ucas.ac.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Kernel Newbies archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernelnewbies/0 kernelnewbies/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernelnewbies kernelnewbies/ https://lore.kernel.org/kernelnewbies \
		kernelnewbies@kernelnewbies.org kernelnewbies@archiver.kernel.org
	public-inbox-index kernelnewbies

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernelnewbies.kernelnewbies


AGPL code for this site: git clone https://public-inbox.org/ public-inbox