Skip to content

Commit

Permalink
Never use current user info or file ownership during build
Browse files Browse the repository at this point in the history
There's no situation where rpmbuild should use uid/gid from either
the filesystem or current user. The former made sense in the
pre-historic times before Buildroot was a thing, but in the last 20+
years that's always the wrong thing to do. Always. The only user/group
info rpm can legitimately use is the one that is explicitly specified in
the packaging, and otherwise fallback to root/equivalent.

Besides fixing a long-standing annoyance with src.rpm file ownership,
this also fixes a regression in 4.19.0 where a non-local or otherwise
unresolvable user info could cause a segfault during rpmbuild (RhBug:2248763).

Fixes: #2604
(backported from commit a0553eb)
  • Loading branch information
pmatilai authored and dmnks committed Dec 12, 2023
1 parent d146585 commit 77d3529
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 38 deletions.
2 changes: 0 additions & 2 deletions build/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <rpm/rpmfileutil.h>
#include "rpmbuild_internal.h"
#include "rpmbuild_misc.h"
#include "rpmug.h"

#include "debug.h"

Expand Down Expand Up @@ -496,7 +495,6 @@ static rpmRC buildSpec(rpmts ts, BTA_t buildArgs, rpmSpec spec, int what)
}
}

rpmugFree();
if (missing_buildreqs && !rc) {
rc = RPMRC_MISSINGBUILDREQUIRES;
}
Expand Down
31 changes: 2 additions & 29 deletions build/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "rpmio_internal.h" /* XXX rpmioSlurp */
#include "rpmfts.h"
#include "rpmfi_internal.h" /* XXX fi->apath */
#include "rpmug.h"
#include "rpmbuild_internal.h"
#include "rpmbuild_misc.h"

Expand Down Expand Up @@ -96,8 +95,6 @@ typedef struct FileListRec_s {
#define fl_ino fl_st.st_ino
#define fl_mode fl_st.st_mode
#define fl_nlink fl_st.st_nlink
#define fl_uid fl_st.st_uid
#define fl_gid fl_st.st_gid
#define fl_rdev fl_st.st_rdev
#define fl_size fl_st.st_size
#define fl_mtime fl_st.st_mtime
Expand Down Expand Up @@ -1143,15 +1140,13 @@ static void genCpioListAndHeader(FileList fl, Package pkg, int isSrc)
if ((flp[1].specdFlags & (SPECD_UID | SPECD_DEFUID)) <
(flp->specdFlags & (SPECD_UID | SPECD_DEFUID)))
{
flp[1].fl_uid = flp->fl_uid;
flp[1].uname = flp->uname;
}

/* gid */
if ((flp[1].specdFlags & (SPECD_GID | SPECD_DEFGID)) <
(flp->specdFlags & (SPECD_GID | SPECD_DEFGID)))
{
flp[1].fl_gid = flp->fl_gid;
flp[1].gname = flp->gname;
}

Expand Down Expand Up @@ -1402,8 +1397,6 @@ static rpmRC addFile(FileList fl, const char * diskPath,
const char *cpioPath;
struct stat statbuf;
mode_t fileMode;
uid_t fileUid;
gid_t fileGid;
const char *fileUname;
const char *fileGname;
rpmRC rc = RPMRC_FAIL; /* assume failure */
Expand Down Expand Up @@ -1492,8 +1485,6 @@ static rpmRC addFile(FileList fl, const char * diskPath,
}

fileMode = statp->st_mode;
fileUid = statp->st_uid;
fileGid = statp->st_gid;

/* Explicit %attr() always wins */
if (fl->cur.ar.ar_fmodestr) {
Expand Down Expand Up @@ -1522,22 +1513,16 @@ static rpmRC addFile(FileList fl, const char * diskPath,
} else if (fl->def.ar.ar_user) {
fileUname = rpmstrPoolStr(fl->pool, fl->def.ar.ar_user);
} else {
fileUname = rpmugUname(fileUid);
fileUname = UID_0_USER;
}
if (fl->cur.ar.ar_group) {
fileGname = rpmstrPoolStr(fl->pool, fl->cur.ar.ar_group);
} else if (fl->def.ar.ar_group) {
fileGname = rpmstrPoolStr(fl->pool, fl->def.ar.ar_group);
} else {
fileGname = rpmugGname(fileGid);
fileGname = GID_0_GROUP;
}

/* Default user/group to builder's user/group */
if (fileUname == NULL)
fileUname = rpmugUname(getuid());
if (fileGname == NULL)
fileGname = rpmugGname(getgid());

/* S_XXX macro must be consistent with type in find call at check-files script */
if (check_fileList && (S_ISREG(fileMode) || S_ISLNK(fileMode))) {
appendStringBuf(check_fileList, diskPath);
Expand All @@ -1555,8 +1540,6 @@ static rpmRC addFile(FileList fl, const char * diskPath,

flp->fl_st = *statp; /* structure assignment */
flp->fl_mode = fileMode;
flp->fl_uid = fileUid;
flp->fl_gid = fileGid;
if (S_ISDIR(fileMode))
flp->fl_size = 0;

Expand Down Expand Up @@ -2780,23 +2763,13 @@ rpmRC processSourceFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags)

if (fl.def.ar.ar_user) {
flp->uname = fl.def.ar.ar_user;
} else {
flp->uname = rpmstrPoolId(fl.pool, rpmugUname(flp->fl_uid), 1);
}
if (! flp->uname) {
flp->uname = rpmstrPoolId(fl.pool, rpmugUname(getuid()), 1);
}
if (! flp->uname) {
flp->uname = rpmstrPoolId(fl.pool, UID_0_USER, 1);
}

if (fl.def.ar.ar_group) {
flp->gname = fl.def.ar.ar_group;
} else {
flp->gname = rpmstrPoolId(fl.pool, rpmugGname(flp->fl_gid), 1);
}
if (! flp->gname) {
flp->gname = rpmstrPoolId(fl.pool, rpmugGname(getgid()), 1);
}
if (! flp->gname) {
flp->gname = rpmstrPoolId(fl.pool, GID_0_GROUP, 1);
Expand Down
1 change: 0 additions & 1 deletion build/parsePrep.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <rpm/rpmfileutil.h>
#include "rpmbuild_internal.h"
#include "rpmbuild_misc.h"
#include "rpmug.h"
#include "debug.h"

static void appendBuf(rpmSpec spec, const char *s, int nl)
Expand Down
9 changes: 3 additions & 6 deletions build/rpmfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <rpm/rpmfi.h>
#include <rpm/rpmstrpool.h>

#include "rpmug.h"
#include "rpmfi_internal.h" /* rpmfiles stuff for now */
#include "rpmbuild_internal.h"

Expand Down Expand Up @@ -1626,16 +1625,14 @@ rpmRC rpmfcGenerateDepends(const rpmSpec spec, Package pkg)
if (rpmExpandNumeric("%{?_use_weak_usergroup_deps}"))
deptag = RPMTAG_RECOMMENDNAME;

/* filter out root and current user/group */
if (user && !rstreq(user, UID_0_USER) &&
!rstreq(user, rpmugUname(getuid()))) {
/* filter out root user/group */
if (user && !rstreq(user, UID_0_USER)) {
rpmds ds = rpmdsSingleNS(fc->pool, deptag, "user",
user, NULL, ugfl);
rpmdsMerge(packageDependencies(pkg, deptag), ds);
rpmdsFree(ds);
}
if (group && !rstreq(group, GID_0_GROUP) &&
!rstreq(group, rpmugGname(getgid()))) {
if (group && !rstreq(group, GID_0_GROUP)) {
rpmds ds = rpmdsSingleNS(fc->pool, deptag, "group",
group, NULL, ugfl);
rpmdsMerge(packageDependencies(pkg, deptag), ds);
Expand Down

0 comments on commit 77d3529

Please sign in to comment.