/*
* Metadata on-disk locking for processes serialization
*
- * Copyright (C) 2016-2021 Red Hat, Inc. All rights reserved.
- * Copyright (C) 2016-2021 Ondrej Kozina
+ * Copyright (C) 2016-2023 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2016-2023 Ondrej Kozina
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
# include <sys/sysmacros.h> /* for major, minor */
#endif
#include <libgen.h>
-#include <assert.h>
#include "internal.h"
#include "utils_device_locking.h"
lockdfd = openat(dirfd, base, O_RDONLY | O_NOFOLLOW | O_DIRECTORY | O_CLOEXEC);
if (lockdfd < 0) {
if (errno == ENOENT) {
- log_dbg(cd, _("Locking directory %s/%s will be created with default compiled-in permissions."), dir, base);
+ log_dbg(cd, "Locking directory %s/%s will be created with default compiled-in permissions.", dir, base);
/* success or failure w/ errno == EEXIST either way just try to open the 'base' directory again */
if (mkdirat(dirfd, base, DEFAULT_LUKS2_LOCK_DIR_PERMS) && errno != EEXIST)
h->u.bdev.devno = st.st_rdev;
h->mode = DEV_LOCK_BDEV;
} else if (S_ISREG(st.st_mode)) {
- // FIXME: workaround for nfsv4
+ /* workaround for nfsv4 */
fd = open(device_path(device), O_RDWR | O_NONBLOCK | O_CLOEXEC);
if (fd < 0)
h->flock_fd = dev_fd;
!stat(res, &buf_b) && /* does path file still exist? */
same_inode(buf_a, buf_b)) { /* is it same id as the one referenced by fd? */
/* coverity[toctou] */
- if (unlink(res)) /* yes? unlink the file */
+ if (unlink(res)) /* yes? unlink the file. lgtm[cpp/toctou-race-condition] */
log_dbg(cd, "Failed to unlink resource file: %s", res);
}
!stat(res, &buf_b) && /* does path file still exist? */
same_inode(buf_a, buf_b)) { /* is it same id as the one referenced by fd? */
/* coverity[toctou] */
- if (unlink(res)) /* yes? unlink the file */
+ if (unlink(res)) /* yes? unlink the file. lgtm[cpp/toctou-race-condition] */
log_dbg(cd, "Failed to unlink resource file: %s", res);
}
return (h && h->type == DEV_LOCK_READ);
}
-static int verify_lock_handle(const char *device_path, struct crypt_lock_handle *h)
+static int verify_lock_handle(struct crypt_lock_handle *h)
{
char res[PATH_MAX];
struct stat lck_st, res_st;
* check whether another libcryptsetup process removed resource file before this
* one managed to flock() it. See release_lock_handle() for details
*/
- r = verify_lock_handle(device_path(device), h);
+ r = verify_lock_handle(h);
if (r < 0) {
if (flock(h->flock_fd, LOCK_UN))
log_dbg(cd, "flock on fd %d failed.", h->flock_fd);
/* if device handle is regular file the handle must match the lock handle */
if (S_ISREG(dev_st.st_mode)) {
- log_dbg(cd, "Veryfing locked device handle (regular file)");
+ log_dbg(cd, "Verifying locked device handle (regular file)");
if (!same_inode(dev_st, lck_st))
return 1;
} else if (S_ISBLK(dev_st.st_mode)) {
- log_dbg(cd, "Veryfing locked device handle (bdev)");
+ log_dbg(cd, "Verifying locked device handle (bdev)");
if (resource_by_devno(res, sizeof(res), dev_st.st_rdev, 1) ||
stat(res, &st) ||
!same_inode(lck_st, st))