Bug 1470124 - glibc: _nl_load_locale_from_archive SIGFPE divide by zero
Summary: glibc: _nl_load_locale_from_archive SIGFPE divide by zero
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: rawhide
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: ---
Assignee: DJ Delorie
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-07-12 12:21 UTC by John Reiser
Modified: 2020-07-13 13:23 UTC (History)
9 users (show)

Fixed In Version: glibc-2.30.9000-12
Clone Of:
Environment:
Last Closed: 2019-10-19 00:47:58 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Sourceware 25115 0 P2 RESOLVED Guard against divide by zero with corrupted locale archives 2020-09-16 08:09:52 UTC

Description John Reiser 2017-07-12 12:21:20 UTC
Description of problem: _nl_load_locale_from_archive defends incompletely against dividing by zero.


Version-Release number of selected component (if applicable):
glibc-2.24-59-g86ac4a7

How reproducible: every time (if particular corruption in locale archive)


Steps to Reproduce:
1. Inspect code for _nl_load_locale_from_archive()
2.
3.

Actual results: In glibc-2.24-59-g86ac4a7/locale/loadarchive.c near lines 277 through 282:
  /* Avoid division by 0 if the file is corrupted.  */
  if (__glibc_unlikely (head->namehash_size == 0))
    goto close_and_out;

  idx = hval % head->namehash_size;
  incr = 1 + hval % (head->namehash_size - 2);

The check defends against dividing by zero in the first modulo operation ('%') but not the second (on the next line).  The check should be expanded to "head->namehash_size <= 2".

The declaration in locarchive.h is
  uint32_t namehash_size;
It seems to me that some heuristic such as (namehash_size >= (0xful << 28)) also is appropriate, to detect extremely unlikely large values [in this case 4,026,531,840 and larger].


Expected results:  Correct defense against dividing by zero in all modulo operations ('%' operator).


Additional info:

Comment 1 Florian Weimer 2017-07-12 12:27:37 UTC
Out of curiosity, how did you encounter this bug?

Comment 2 John Reiser 2017-07-12 12:56:30 UTC
(In reply to Florian Weimer from comment #1)
> Out of curiosity, how did you encounter this bug?

A side effect of investigating https://bugzilla.redhat.com/show_bug.cgi?id=1468778

Comment 3 Fedora End Of Life 2017-11-16 18:37:32 UTC
This message is a reminder that Fedora 25 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 25. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '25'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version'
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not
able to fix it before Fedora 25 is end of life. If you would still like
to see this bug fixed and are able to reproduce it against a later version
of Fedora, you are encouraged  change the 'version' to a later Fedora
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.

Comment 4 John Reiser 2017-11-20 02:57:53 UTC
The problem persists in
  glibc-2.26-65-ga76376df7c
which is the source for
  glibc-2.26-16.fc27.x86_64

Comment 5 Ben Cotton 2018-11-27 18:08:24 UTC
This message is a reminder that Fedora 27 is nearing its end of life.
On 2018-Nov-30  Fedora will stop maintaining and issuing updates for
Fedora 27. It is Fedora's policy to close all bug reports from releases
that are no longer maintained. At that time this bug will be closed as
EOL if it remains open with a Fedora  'version' of '27'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 27 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 6 Ben Cotton 2019-02-19 17:11:40 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 30 development cycle.
Changing version to '30.

Comment 9 DJ Delorie 2019-10-19 00:47:58 UTC
Fixed in upstream ef21bd2d8c6805c0c186a01f7c5039189f51b8c4


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