Skip to content

Commit

Permalink
audit: fix a race in the file timestamp
Browse files Browse the repository at this point in the history
Before that the code was setting the timestamp of the file on the
http server to the compressed file but never to the uncompressed one
but to decide if a new version should be fetched pkg gets the mtime
from the uncompressed file.

Reported by:	dvl
  • Loading branch information
bapt committed Oct 13, 2023
1 parent d1d9a3f commit 2fe36a5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libpkg/pkg_audit.c
Expand Up @@ -201,6 +201,14 @@ pkg_audit_fetch(const char *src, const char *dest)
struct stat st;
struct pkg_audit_extract_cbdata cbdata;
int dfd = -1;
struct timeval tm[2] = {
{
.tv_usec = 0
},
{
.tv_usec = 0
}
};

if (src == NULL) {
src = pkg_object_string(pkg_config_get("VULNXML_SITE"));
Expand Down Expand Up @@ -254,9 +262,13 @@ pkg_audit_fetch(const char *src, const char *dest)
cbdata.fname = tmp;
cbdata.out = outfd;
cbdata.dest = dest;
fstat(fd, &st);

/* Call sandboxed */
retcode = pkg_emit_sandbox_call(pkg_audit_sandboxed_extract, fd, &cbdata);
tm[0].tv_sec = st.st_mtim.tv_sec;
tm[1].tv_sec = st.st_mtim.tv_sec;
futimes(outfd, tm);

cleanup:
unlink(tmp);
Expand Down

3 comments on commit 2fe36a5

@dlangille
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patched pkg here, installed it on a problem host, ran pkg audit -F, curl 8.4.0 is still vuln. Am I doing this right?

@bapt
Copy link
Member Author

@bapt bapt commented on 2fe36a5 Oct 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked locally once curl 8.4.0 is installed, curl is not a vuln anymore, so everything is fine

@dlangille
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

However, I have monitoring checks for pkg audit failures. There were still alerting. I cleared them out via rm /var/db/pkg/vuln.xml; pkg audit -F - re https://dan.langille.org/2023/10/13/got-a-pkg-vuln-you-cant-get-rid-of/

Thank you for fixing.

Please sign in to comment.