flat assembler
Message board for the users of flat assembler.

Index > Linux > Linux kernel 2.6.11 requires writeable .bss section

Author
Thread Post new topic Reply to topic
ccrayne



Joined: 17 May 2005
Posts: 12
ccrayne
Changes to the binfmt_elf.c routine in the Linux 2.6.11 kernal now cause a segment fault if the ELF header has a pointer to a read-only .bss section. This causes (e.g.) the "hello" program in ../examples/elfexe to fail. One can argue if the new kernel code is a bug or a feature, but it would be a good idea for the flat assembler developers to fix the problem, since a .bss section which is not writeable isn't of any use, in any case.

-- Chuck
Post 25 Jun 2005, 05:50
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
But the fasm's examples don't contain any BSS section at all. As you can see in the source, there is one "section readable writeable" for data and one "section readable executable" for code - these are in fact only segments in the program header, since fasm follows strictly the ELF specification, which states that section headers are optional (thus not needed) for the executables and program headers are optional for the objects.
Post 25 Jun 2005, 10:03
View user's profile Send private message Visit poster's website Reply with quote
ccrayne



Joined: 17 May 2005
Posts: 12
ccrayne
Nevertheless, when I force a writeable BSS section, by adding the following lines to the example, the problem goes away:

section readable writeable
dummy dd ?

-- Chuck
Post 25 Jun 2005, 17:28
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
Maybe the problem is not having BSS section at all? Does the kernel (over)interprete that the last section of program is always the BSS?
Post 25 Jun 2005, 17:38
View user's profile Send private message Visit poster's website Reply with quote
ccrayne



Joined: 17 May 2005
Posts: 12
ccrayne
You are correct, as I have just verified by digging deeper into the kernel code [binfmt_elf.c], and by running a few tests. The kernel wants to clear the uninitialized part of the last page, and calculates the address to start zeroing by finding the section with the highest physical address pointer, and adding the memory size value for that section.

In the case of the elfexe example program, the last section is the code section, and is not writeable, so the attempt to zero the rest of the page fails. In earlier releases, the return code from the padzero call was not checked, but starting with the 2.6.11 kernel, a non-zero return code causes a segment fault.

Although it seems to me that this new behavior is a kernel bug, I still think that it is in your best interest to change to code to ensure that the last section is something writeable, even if it is only a zero length section.

-- Chuck
Post 25 Jun 2005, 23:41
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7725
Location: Kraków, Poland
Tomasz Grysztar
This is only the matter of changing the example source - fasm itself just creates the sections in the order and type exactly as it told to do by the source.
Post 26 Jun 2005, 00:00
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Yay for excellent linux kernel programmers - *grin*
Post 26 Jun 2005, 14:59
View user's profile Send private message Visit poster's website Reply with quote
ccrayne



Joined: 17 May 2005
Posts: 12
ccrayne
Further testing shows that the the "dummy dd ?" in my previous post is not required. Adding "section writable" is sufficient, by itself.
Post 26 Jun 2005, 20:07
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
Quote:

Yay for excellent linux kernel programmers - *grin*

-
Quote:

You are correct, as I have just verified by digging deeper into the kernel code [binfmt_elf.c]


Yay for open source kernel development Wink
Post 27 Jun 2005, 12:54
View user's profile Send private message Yahoo Messenger Reply with quote
scientica
Retired moderator


Joined: 16 Jun 2003
Posts: 689
Location: Linköping, Sweden
scientica
I 2nd that, wonder how long time would a such design choice would have been an "unknown why" in *cough* *cough* ...
btw, does this behaviour still exist in 2.6.12? (haven't dug the sources at time of writing, I wonder is it documented or possibly a thing that should be patched asap?)
Post 05 Jul 2005, 15:24
View user's profile Send private message Visit poster's website Reply with quote
ccrayne



Joined: 17 May 2005
Posts: 12
ccrayne
Quote:

btw, does this behaviour still exist in 2.6.12?

Yes, I am now running 2.6.12-1.1387_FC4, and the behaviour is unchanged. As far as I know, elfexe is the only publicly distributed code which shows this problem , so I fear that it will go down in history as a flat assembler bug.

-- Chuck
Post 10 Jul 2005, 22:52
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Quote:

so I fear that it will go down in history as a flat assembler bug.

...even though, considering the nature of things, it's a linux bug.
Post 10 Jul 2005, 22:58
View user's profile Send private message Visit poster's website Reply with quote
ccrayne



Joined: 17 May 2005
Posts: 12
ccrayne
Quote:

...even though, considering the nature of things, it's a linux bug.


Yes, even though . . .

-- Chuck
Post 12 Jul 2005, 06:04
View user's profile Send private message Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509
Thanks for the info. I was wandering why my code was no longer working!
Post 13 Jul 2005, 00:19
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Anyone knows if the newer versions of the linux kernel has this problem too? Someone had reported this to the Linux developers?
Post 08 Feb 2006, 15:55
View user's profile Send private message Reply with quote
maxhrk



Joined: 04 Mar 2006
Posts: 4
maxhrk
i has to travel to past of slashdot and fetch some information why there are change to elf in 2.6.11 heh...

here two links:

http://it.slashdot.org/article.pl?sid=05/05/30/1111206
http://lwn.net/Articles/136516/

cheer. Very Happy
Post 04 Mar 2006, 11:26
View user's profile Send private message Reply with quote
ccrayne



Joined: 17 May 2005
Posts: 12
ccrayne
locodelassembly wrote:
Anyone knows if the newer versions of the linux kernel has this problem too?


A fix for this problem was included in 2.6.14. I have tested it with 2.6.15 and 2.6.16, and agree that the problem is now fixed.

-- Chuck
Post 23 Apr 2006, 06:30
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Thanks chuck!!
Post 23 Apr 2006, 14:22
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
OK, i am going to un-Sticky this thread
Post 10 Oct 2006, 17:07
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.