public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "David S. Miller" <davem@davemloft.net>
To: dan@debian.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: fs/binfmt_elf.c:maydump()
Date: Thu, 06 Apr 2006 22:18:07 -0700 (PDT)	[thread overview]
Message-ID: <20060406.221807.114721185.davem@davemloft.net> (raw)
In-Reply-To: <20060406.153518.60508780.davem@davemloft.net>

From: "David S. Miller" <davem@davemloft.net>
Date: Thu, 06 Apr 2006 15:35:18 -0700 (PDT)

> With this patch applied, yes, it includes the complete text segments of
> every executable and shared library mapped into the program which is
> dumping core.

I did some more research and the 2.4.x kernel currently does
the test like this:

static inline int maydump(struct vm_area_struct *vma)
{
	/*
	 * If we may not read the contents, don't allow us to dump
	 * them either. "dump_write()" can't handle it anyway.
	 */
	if (!(vma->vm_flags & VM_READ))
		return 0;

	/* Do not dump I/O mapped devices! -DaveM */
	if (vma->vm_flags & VM_IO)
		return 0;
#if 1
	if (vma->vm_flags & (VM_WRITE|VM_GROWSUP|VM_GROWSDOWN))
		return 1;
	if (vma->vm_flags & (VM_READ|VM_EXEC|VM_EXECUTABLE|VM_SHARED))
		return 0;
#endif
	return 1;
}

Ok, if it's not readable don't put it into the core file, fine.
If it's an I/O mapping, skip it too, also makes sense.

The next check forces dumping of any wriable or stack segments.

The function always terminates at the next check, because VM_READ
is guarenteed to be set if we get here.  The first thing we
checked is if VM_READ was clear at the very top of the function.

Yikes...

Anyways, so what's exactly happening in 2.6.x right now?

static int maydump(struct vm_area_struct *vma)
{
	/* Do not dump I/O mapped devices or special mappings */
	if (vma->vm_flags & (VM_IO | VM_RESERVED))
		return 0;

	/* Dump shared memory only if mapped from an anonymous file.  */
	if (vma->vm_flags & VM_SHARED)
		return vma->vm_file->f_dentry->d_inode->i_nlink == 0;

	/* If it hasn't been written to, don't write it out */
	if (!vma->anon_vma)
		return 0;

	return 1;
}

Skip reserved or I/O mappings, ok.

Else skip shared mappings of non-anonymous files.  I'm not so sure
about this check.

Else skip any mapping not written to yet.  I still think at this
point the logic is wrong.

How about something like the following patch?  If it's executable
and not written to, skip it.  This would skip the main executable
image and all text segments of the shared libraries mapped in.

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 537893a..9ec5c2b 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1167,8 +1167,10 @@ static int maydump(struct vm_area_struct
 	if (vma->vm_flags & VM_SHARED)
 		return vma->vm_file->f_dentry->d_inode->i_nlink == 0;
 
-	/* If it hasn't been written to, don't write it out */
-	if (!vma->anon_vma)
+	/* If it is executable and hasn't been written to,
+	 * don't write it out.
+	 */
+	if ((vma->vm_flags & VM_EXEC) && !vma->anon_vma)
 		return 0;
 
 	return 1;


  reply	other threads:[~2006-04-07  5:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-06 21:03 fs/binfmt_elf.c:maydump() David S. Miller
2006-04-06 22:15 ` fs/binfmt_elf.c:maydump() Daniel Jacobowitz
2006-04-06 22:35   ` fs/binfmt_elf.c:maydump() David S. Miller
2006-04-07  5:18     ` David S. Miller [this message]
2006-04-07 18:02       ` fs/binfmt_elf.c:maydump() Daniel Jacobowitz
2006-04-07 20:27         ` fs/binfmt_elf.c:maydump() David S. Miller
2006-04-10 13:01           ` fs/binfmt_elf.c:maydump() Daniel Jacobowitz
2007-01-03  2:02       ` Contents of core dumps (was: Re: fs/binfmt_elf.c:maydump()) Daniel Jacobowitz
2007-01-03  4:57         ` Contents of core dumps David Miller
2007-01-03 18:13           ` Daniel Jacobowitz

Reply instructions:

You may reply publicly 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=20060406.221807.114721185.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=dan@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox