alpine 3.6
access weakness #227

1

Weakness Breakdown


Definition:

An access weakness occurs when software does not properly implement permissions that could have unintended consequences if exploited by malicious actors. An example of this weakness is when a default username and password are set by the developer but do not get changed by the system administrator.

Warning code(s):

Ensure that umask is given most restrictive possible setting.

File Name:

powerpc-utils/src/powerpc-utils-1.3.3/src/drmgr/common.c

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.6 access weakness.

 }

/**
 * dr_lock
 * @brief Attempt to lock a token
 *
 * This will attempt to lock a token (either file or directory) and wait
 * a specified amount of time if the lock cannot be granted.
 *
 * @returns lock id if successful, -1 otherwise
 */
int dr_lock(void)
{
	struct flock    dr_lock_info;
	int             rc;
	mode_t          old_mode;
	int             first_try = 1;

	old_mode = umask(0);
	dr_lock_fd = open(DR_LOCK_FILE, O_RDWR | O_CREAT,
			  S_IRUSR | S_IRGRP | S_IROTH);
	if (dr_lock_fd < 0)
		return -1;

	umask(old_mode);
	dr_lock_info.l_type = F_WRLCK;
	dr_lock_info.l_whence = SEEK_SET;
	dr_lock_info.l_start = 0;
	dr_lock_info.l_len = 0;

	do {
		if (!first_try) {
			sleep(1);
			first_try = 0;
		}

		rc = fcntl(dr_lock_fd, F_SETLK, &dr_lock_info);
		if (rc != -1)
			return 0;

		if (drmgr_timed_out())
			break;

		if (rc == -1 && errno == EACCES)
			continue;

	} while (1);

	close(dr_lock_fd);
	dr_lock_fd = 0; 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.