This bug has been migrated to another issue tracking site. It has been closed here and may no longer be being monitored.

If you would like to get updates for this issue, or to participate in it, you may do so at Red Hat Issue Tracker .
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2211215 - clang TSA does not analyze __attribute__((cleanup)) functions
Summary: clang TSA does not analyze __attribute__((cleanup)) functions
Keywords:
Status: CLOSED MIGRATED
Alias: None
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: clang
Version: 9.2
Hardware: Unspecified
OS: Unspecified
high
unspecified
Target Milestone: rc
: ---
Assignee: Timm Bäder
QA Contact: Jesus Checa
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-05-30 19:09 UTC by Stefan Hajnoczi
Modified: 2023-08-24 13:19 UTC (History)
8 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-08-24 13:19:58 UTC
Type: Bug
Target Upstream Version:
Embargoed:
pm-rhel: mirror+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker   RHEL-1650 0 None Migrated None 2023-08-24 13:15:03 UTC
Red Hat Issue Tracker RHELPLAN-158610 0 None None None 2023-05-30 19:11:39 UTC

Description Stefan Hajnoczi 2023-05-30 19:09:20 UTC
Description of problem:
clang's Thread Safety Analysis does not take into account __attribute__((cleanup)). Therefore it misses lock guards and similar patterns where a resource is released in an __attribute__((cleanup)) function.

This appears to affect both C and C++ programs. The use of __attribute__((cleanup)) is somewhat common in QEMU because it is a C program without C++ RAII abilities.

Version-Release number of selected component (if applicable):
clang-15.0.7-2.el9.x86_64

How reproducible:
100%

Steps to Reproduce:
1. $ cat >a.c
#include <assert.h>
#include <pthread.h>

typedef pthread_mutex_t __attribute__((capability("mutex"))) mutex;

static mutex lock = PTHREAD_MUTEX_INITIALIZER;
static int counter __attribute__((guarded_by(lock)));

void mutex_lock(mutex *m) __attribute__((acquire_capability(lock))) __attribute__((no_thread_safety_analysis))
{
    pthread_mutex_lock(m);
}

void mutex_unlock(mutex *m) __attribute__((release_capability(lock))) __attribute__((no_thread_safety_analysis))
{
    pthread_mutex_unlock(m);
}

struct guard
{
    /* Nothing */
};

static void guard_cleanup(struct guard *unused) __attribute__((release_capability(lock)))
{
    mutex_unlock(&lock);
}

int main(int argc, char **argv)
{
    {
        mutex_lock(&lock);
        struct guard __attribute__((cleanup(guard_cleanup))) guard;

        counter++;
    }

    counter--; /* this should fail */
    return 0;
}
^D
2. clang -Wthread-safety -o a a.c

Actual results:
a.c:40:1: warning: mutex 'lock' is still held at the end of function [-Wthread-safety-analysis]
}
^
a.c:32:9: note: mutex acquired here
        mutex_lock(&lock);
        ^
1 warning generated.

This is wrong. The lock is released in guard_cleanup() before the scope inside main() ends.

Expected results:
A warning should identify that counter-- accesses the field without holding the lock.

Additional info:

Comment 1 Stephen Coady 2023-08-24 13:09:55 UTC
This bug is about to be migrated to the RHEL project in JIRA. Once done, this bug should automatically be closed with a reference link to the new JIRA. Please continue any conversations there. For any questions, you can contact either me or Timm Bäder.

Comment 2 RHEL Program Management 2023-08-24 13:13:08 UTC
Issue migration from Bugzilla to Jira is in process at this time. This will be the last message in Jira copied from the Bugzilla bug.

Comment 3 RHEL Program Management 2023-08-24 13:19:58 UTC
This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there.

To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "RHEL-" followed by an integer.  You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like:

"Bugzilla Bug" = 1234567

In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues.


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