Bug 2428281 - binutils: Refuse to create text relocations by default
Summary: binutils: Refuse to create text relocations by default
Keywords:
Status: MODIFIED
Alias: None
Product: Fedora
Classification: Fedora
Component: binutils
Version: rawhide
Hardware: Unspecified
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Nick Clifton
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
: 2436257 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2026-01-09 16:49 UTC by Florian Weimer
Modified: 2026-03-19 19:31 UTC (History)
14 users (show)

Fixed In Version: binutils-2.45.50-15.fc44
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Florian Weimer 2026-01-09 16:49:22 UTC
I noticed that building this:

```
int x;

int
f (void)
{
  return x;
}
```

with: gcc `rpm --eval "%build_cflags %build_ldflags"` -m32 -fno-pic t.c -shared

still produces an executable. There is a warning:

/usr/bin/ld: warning: creating DT_TEXTREL in a shared object

But exit status is zero, and there is an output file.

I think we should ban text relocations in the same way we banned RWX segments.

This is probably an item for after the mass rebuild.

Reproducible: Always

Comment 1 Nick Clifton 2026-01-14 12:00:27 UTC
Fixed in binutils-2.45.50-15.fc44 

More specifically I have added a definable option to the binutils.spec file:

  # Enable the creation of relocations against the contents of read-only
  # sections (such as .text).  This is a security vulnerability, so it is
  # disabled here by default.
  # Note - the upstream GNU Binutils sources enable the generation of this
  # kind of relocation by default, so this is a difference between Fedora
  # and upstream.
  %define enable_textrel 0

Comment 2 Jens Petersen 2026-01-17 14:37:41 UTC
Just noting this broke ghc on i686.
Though I have a new patch in hand to remove a hack that causes it (see bug 2430571).

It may also have affected fpc.

Comment 3 Nick Clifton 2026-01-19 09:27:49 UTC
FYI - for any future readers of this ticket:

The simplest way to stop the linker from issuing this error message is to add "-Wl,-z,notext" to the command line.

Comment 4 Sergio Basto 2026-02-02 23:24:22 UTC
(In reply to Nick Clifton from comment #1)
> Fixed in binutils-2.45.50-15.fc44 
> 
> More specifically I have added a definable option to the binutils.spec file:
> 
>   # Enable the creation of relocations against the contents of read-only
>   # sections (such as .text).  This is a security vulnerability, so it is
>   # disabled here by default.
>   # Note - the upstream GNU Binutils sources enable the generation of this
>   # kind of relocation by default, so this is a difference between Fedora
>   # and upstream.
>   %define enable_textrel 0

how we disable this security feature ? , VirtualBox , x264 , fffmpeg and x265 have this warning: relocation in read-only section `.text'

Comment 5 Nick Clifton 2026-02-03 14:57:43 UTC
(In reply to Sergio Basto from comment #4)
 
> how we disable this security feature ?

Add "-Wl,-z,notext" to the compiler command line.

Ideally if you do add this option, it would be good to also include a comment as to why it is needed.  Being able to modify read-only sections of an executable, especially the code, at run time is an obvious vulnerability.  So there really should be a good reason for allowing it.  Or at least a reason why the code being vulnerable is not going to affect the system as a whole.

Comment 6 Nicolas Chauvet (kwizart) 2026-02-03 15:51:51 UTC
*** Bug 2436257 has been marked as a duplicate of this bug. ***

Comment 7 Yaakov Selkowitz 2026-02-10 00:18:18 UTC
In ffmpeg and libass, this may be connected to nasm-generated code, but only on i686.

https://koji.fedoraproject.org/koji/taskinfo?taskID=142127825
https://koji.fedoraproject.org/koji/taskinfo?taskID=142127835

Comment 9 Kevin Fenzi 2026-03-19 19:31:35 UTC
This seems to be affecting i686 builds of openh264 also, and I think for the same reason (nasm generated code)


Note You need to log in before you can comment on or make changes to this bug.