summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2023-07-04 20:40:22 +0000
committerriastradh <riastradh@NetBSD.org>2023-07-04 20:40:22 +0000
commitc6b08bc954d661a894cc6cdd8394a3b49ce37d8a (patch)
tree4bbf47c1fb6eb881224b6f8ab273a23fb00bc7b5 /sbin
parent16cfaeb0a9dea1c68c471791b89eedb67e991a1f (diff)
fsck_ffs(8): Ensure A divides S before aligned_alloc(A, S).
Required by C11 Sec. 7.22.3.1 The aligned_alloc function, para. 2, p. 348: The value of alignment shall be a valid alignment supported by the implementation and the value of size shall be an integral multiple of alignment. XXX pullup-10
Diffstat (limited to 'sbin')
-rw-r--r--sbin/fsck_ffs/inode.c8
-rw-r--r--sbin/fsck_ffs/setup.c16
-rw-r--r--sbin/fsck_ffs/utilities.c13
3 files changed, 25 insertions, 12 deletions
diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c
index 82f84111ee2..540d8a4ca2b 100644
--- a/sbin/fsck_ffs/inode.c
+++ b/sbin/fsck_ffs/inode.c
@@ -1,4 +1,4 @@
-/* $NetBSD: inode.c,v 1.75 2023/01/14 17:01:10 kre Exp $ */
+/* $NetBSD: inode.c,v 1.76 2023/07/04 20:40:22 riastradh Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)inode.c 8.8 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: inode.c,v 1.75 2023/01/14 17:01:10 kre Exp $");
+__RCSID("$NetBSD: inode.c,v 1.76 2023/07/04 20:40:22 riastradh Exp $");
#endif
#endif /* not lint */
@@ -462,8 +462,10 @@ setinodebuf(ino_t inum)
partialcnt = fullcnt;
partialsize = inobufsize;
}
+ __CTASSERT(powerof2(DEV_BSIZE));
if (inodebuf == NULL &&
- (inodebuf = aligned_alloc(DEV_BSIZE, (unsigned)inobufsize)) == NULL)
+ (inodebuf = aligned_alloc(DEV_BSIZE,
+ roundup2((unsigned)inobufsize, DEV_BSIZE))) == NULL)
errexit("Cannot allocate space for inode buffer");
}
diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c
index 7a95cb5a3da..9b16ea55ce9 100644
--- a/sbin/fsck_ffs/setup.c
+++ b/sbin/fsck_ffs/setup.c
@@ -1,4 +1,4 @@
-/* $NetBSD: setup.c,v 1.106 2023/01/08 05:25:24 chs Exp $ */
+/* $NetBSD: setup.c,v 1.107 2023/07/04 20:40:22 riastradh Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)setup.c 8.10 (Berkeley) 5/9/95";
#else
-__RCSID("$NetBSD: setup.c,v 1.106 2023/01/08 05:25:24 chs Exp $");
+__RCSID("$NetBSD: setup.c,v 1.107 2023/07/04 20:40:22 riastradh Exp $");
#endif
#endif /* not lint */
@@ -127,6 +127,7 @@ setup(const char *dev, const char *origdev)
lfdir = 0;
initbarea(&sblk);
initbarea(&asblk);
+ __CTASSERT((SBLOCKSIZE % DEV_BSIZE) == 0);
sblk.b_un.b_buf = aligned_alloc(DEV_BSIZE, SBLOCKSIZE);
sblock = aligned_alloc(DEV_BSIZE, SBLOCKSIZE);
asblk.b_un.b_buf = aligned_alloc(DEV_BSIZE, SBLOCKSIZE);
@@ -459,8 +460,9 @@ setup(const char *dev, const char *origdev)
* read in the summary info.
*/
asked = 0;
+ __CTASSERT(powerof2(DEV_BSIZE));
sblock->fs_csp = (struct csum *)aligned_alloc(DEV_BSIZE,
- sblock->fs_cssize);
+ roundup2(sblock->fs_cssize, DEV_BSIZE));
if (sblock->fs_csp == NULL) {
pwarn("cannot alloc %u bytes for summary info\n",
sblock->fs_cssize);
@@ -495,7 +497,9 @@ setup(const char *dev, const char *origdev)
* allocate and initialize the necessary maps
*/
bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(int16_t));
- blockmap = aligned_alloc(DEV_BSIZE, (unsigned)bmapsize);
+ __CTASSERT(powerof2(DEV_BSIZE));
+ blockmap = aligned_alloc(DEV_BSIZE,
+ roundup2((unsigned)bmapsize, DEV_BSIZE));
if (blockmap == NULL) {
pwarn("cannot alloc %u bytes for blockmap\n",
(unsigned)bmapsize);
@@ -530,7 +534,9 @@ setup(const char *dev, const char *origdev)
(unsigned)(numdirs * sizeof(struct inoinfo *)));
goto badsblabel;
}
- cgrp = aligned_alloc(DEV_BSIZE, sblock->fs_cgsize);
+ __CTASSERT(powerof2(DEV_BSIZE));
+ cgrp = aligned_alloc(DEV_BSIZE,
+ roundup2(sblock->fs_cgsize, DEV_BSIZE));
if (cgrp == NULL) {
pwarn("cannot alloc %u bytes for cylinder group\n",
sblock->fs_cgsize);
diff --git a/sbin/fsck_ffs/utilities.c b/sbin/fsck_ffs/utilities.c
index 27403a389da..6f0086052a2 100644
--- a/sbin/fsck_ffs/utilities.c
+++ b/sbin/fsck_ffs/utilities.c
@@ -1,4 +1,4 @@
-/* $NetBSD: utilities.c,v 1.68 2023/01/14 12:12:50 christos Exp $ */
+/* $NetBSD: utilities.c,v 1.69 2023/07/04 20:40:22 riastradh Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)utilities.c 8.6 (Berkeley) 5/19/95";
#else
-__RCSID("$NetBSD: utilities.c,v 1.68 2023/01/14 12:12:50 christos Exp $");
+__RCSID("$NetBSD: utilities.c,v 1.69 2023/07/04 20:40:22 riastradh Exp $");
#endif
#endif /* not lint */
@@ -135,12 +135,15 @@ bufinit(void)
char *bufp;
pbp = pdirbp = (struct bufarea *)0;
- bufp = aligned_alloc(DEV_BSIZE, (unsigned int)sblock->fs_bsize);
+ __CTASSERT(powerof2(DEV_BSIZE));
+ bufp = aligned_alloc(DEV_BSIZE,
+ roundup2((unsigned int)sblock->fs_bsize, DEV_BSIZE));
if (bufp == 0)
errexit("cannot allocate buffer pool");
cgblk.b_un.b_buf = bufp;
initbarea(&cgblk);
#ifndef NO_APPLE_UFS
+ __CTASSERT((APPLEUFS_LABEL_SIZE % DEV_BSIZE) == 0);
bufp = aligned_alloc(DEV_BSIZE, (unsigned int)APPLEUFS_LABEL_SIZE);
if (bufp == 0)
errexit("cannot allocate buffer pool");
@@ -153,7 +156,9 @@ bufinit(void)
bufcnt = MINBUFS;
for (i = 0; i < bufcnt; i++) {
bp = malloc(sizeof(struct bufarea));
- bufp = aligned_alloc(DEV_BSIZE, (unsigned int)sblock->fs_bsize);
+ __CTASSERT(powerof2(DEV_BSIZE));
+ bufp = aligned_alloc(DEV_BSIZE,
+ roundup2((unsigned int)sblock->fs_bsize, DEV_BSIZE));
if (bp == NULL || bufp == NULL) {
if (i >= MINBUFS) {
if (bp)