Bug 2099930 - Macro SH_TAILQ_NEXT may cause a potential infinite loop in libdb
Summary: Macro SH_TAILQ_NEXT may cause a potential infinite loop in libdb
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: libdb
Version: 36
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Filip Januš
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-06-22 02:45 UTC by freshmakeruser
Modified: 2023-05-25 16:17 UTC (History)
8 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2023-05-25 16:17:17 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Attached is the fix patch (889 bytes, application/mbox)
2022-06-22 02:45 UTC, freshmakeruser
no flags Details

Description freshmakeruser 2022-06-22 02:45:14 UTC
Created attachment 1891791 [details]
Attached is the fix patch

src/dbinc/shqueue.h:264
SH_TAILQ_NEXT macro may cause a potential infinite loop

src/mp/mp_alloc.c:306
Iterate through the buffer list
SH_TAILQ_FOREACH(current_bhp, &hp->hash_bucket, hq, __bh) {

src/dbinc/shqueue.h:316

#define SH_TAILQ_FOREACH(var, head, field, type)                        \
        for ((var) = SH_TAILQ_FIRST((head), type);                      \
            (var) != NULL;                                              \
            (var) = SH_TAILQ_NEXT((var), field, type))

src/dbinc/shqueue.h:264
#define SH_TAILQ_NEXT(elm, field, type)                                 \
        ((elm)->field.stqe_next == -1 ? NULL :                          \
        ((struct type *)((u_int8_t *)(elm) + (elm)->field.stqe_next)))

When (elm)->field.stqe_next is 0, src/mp/mp_alloc.c:306 will be trapped in a infinite loop because the buffer traversed to is still itself.

The robustness of the program should be guaranteed within the SH_TAILQ_NEXT macro, and the call point should not be expected not to pass in an exception value.

Modify the code attached to mp_alloc.c:306 so that the field.stqe_next of a certain buffer is 0. It is easy to dummy out and the program is stuck in a infinite loop.

Therefore (elm)->field.stqe_next == 0 should also be the termination condition to determine.
At this point, jump out of the loop and continue to traverse the next hash bucket, rather than repeatedly traverse the same buffer and fall into a infinite loop.

Attached is the fix patch.

Comment 1 Ben Cotton 2023-04-25 17:29:02 UTC
This message is a reminder that Fedora Linux 36 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora Linux 36 on 2023-05-16.
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
'version' of '36'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, change the 'version' 
to a later Fedora Linux version. Note that the version field may be hidden.
Click the "Show advanced fields" button if you do not see it.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora Linux 36 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 Linux, you are encouraged to change the 'version' to a later version
prior to this bug being closed.

Comment 2 Ludek Smid 2023-05-25 16:17:17 UTC
Fedora Linux 36 entered end-of-life (EOL) status on 2023-05-16.

Fedora Linux 36 is no longer maintained, which means that it
will not receive any further security or bug fix updates. As a result we
are closing this bug.

If you can reproduce this bug against a currently maintained version of Fedora Linux
please feel free to reopen this bug against that version. Note that the version
field may be hidden. Click the "Show advanced fields" button if you do not see
the version field.

If you are unable to reopen this bug, please file a new report against an
active release.

Thank you for reporting this bug and we are sorry it could not be fixed.


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