Commit Graph

5861 Commits

Author SHA1 Message Date
rillig 2676d01412 lint: rename dcs manipulation functions to be clearer
No functional change.
2022-08-28 08:41:06 +00:00
rillig c588212fb6 tests/lint: add more information to test for __attribute__((aligned))
Declaring an array type having a negative dimension is the simplest way
to embed an integer into a lint diagnostic, thereby revealing what size
and alignment lint has calculated for a struct.

While here, move these "compile-time assertions" closer to their
corresponding struct, to make reading easier.
2022-08-27 23:24:37 +00:00
rillig 68d3211991 tests/lint: add another test for aligned struct member
In the kernel, several structs have this attribute, and running lint on
them runs into a compile-time assertion.  Typical error messages are:

* error: illegal bit-field size: 255 [36]
* error: integral constant expression expected [55]
2022-08-27 21:59:41 +00:00
christos 5dd94c5e95 Add sincos{,f,l} from FreeBSD 2022-08-27 08:31:58 +00:00
rillig a649f3d0e9 lint: remove explicit list of known GCC attributes
Most GCC attributes consist of a single identifier.  Up to now, it was
necessary to list each of these identifiers in the grammar, even those
that only apply to a single target architecture.

Instead, parse the general form of attributes, matching the few
attributes that lint handles by name instead.  While here, rename the
grammar rules to use the GCC terms.

To avoid conflicts between the global function 'printf' and the GCC
attribute of the same name, do not add GCC attributes to the symbol
table, and don't make these symbols 'extern' either.

ok christos@.
2022-08-25 19:03:47 +00:00
mlelstv c0019d5261 requires pmap_private.h now. 2022-08-21 14:06:42 +00:00
rillig e8f3e4bdea lint: add more details to message about large bit-shifts 2022-08-19 19:40:39 +00:00
rillig a45115be53 tests/lint: demonstrate wrong warning about bit-shift 2022-08-19 19:13:04 +00:00
hannken e14a6c8694 When run from py-anita/amd64 this test fails with:
cgdconfig: getfsspecname failed: no match for `wd0e'

as the virtual machine has root on dk0, dk0 at wd0 and trying to
open wd0e fails.

This tests runs without a rump kernel and therefore should not
even try to open configured devices on the host.  Replace the
disks "wd0e" and "ld1e" with non-existant disks "dska" and "dskb".
2022-08-13 17:46:26 +00:00
isaki aa3450bc70 audiotest: Add two tests for AUDIO_SETINFO after mmap.
These tests affect only standalone test, not atf.
2022-08-13 07:22:40 +00:00
isaki 248c923741 audiotest: Fix typo in comments. 2022-08-13 07:19:15 +00:00
isaki 00cd774dfc audiotest: Separate mmap_len test by parameters.
This change affects only standalone test, not atf.
2022-08-13 07:14:40 +00:00
riastradh fdfb7cab0e membar(3): Fix t_spinlock for machines with hash-locked atomics.
Regular stores don't participate in the hash-locking scheme, so use
atomic_swap instead of a regular store here.
2022-08-12 11:21:44 +00:00
riastradh 920e28df65 cgdconfig(8): Add support for shared keys.
New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

  Suppose your budget is time t before you get bored, and you
  calibrate password hash parameters to unlock n disks before you get
  bored waiting for `cgdconfig -C'.

  . With n password hashings the adversary's cost goes up only by a
    factor of t/n.
  . With one password hashing and n subkeys the adversary's cost goes
    up by a factor of n.

  And if you ever add a disk, rehashing it will make `cgdconfig -C'
  go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
  which could be used to get a key from a hardware token that needs a
  button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same.  With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

	algorithm aes-cbc;
	iv-method encblkno1;
	keylength 128;
	verify_method none;
	keygen pkcs5_pbkdf2/sha1 {
		iterations 39361;
		salt AAAAgMoHiYonye6KogdYJAobCHE=;
		shared "pw" algorithm hkdf-hmac-sha256
		    subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
	};

The key used for this disk will be derived by

	HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
2022-08-12 10:49:17 +00:00
riastradh 732db29a3c cgdconfig(8): New -T operation prints all generated keys in cgd.conf.
For testing purposes.
2022-08-12 10:48:44 +00:00
riastradh a7c16118d0 cgdconfig(8): New -t operation just prints the derived key in base64.
For testing purposes.
2022-08-12 10:48:27 +00:00
charlotte f5524c7c97 Add a TNF copyright statement in t_mixerctl.sh 2022-08-10 00:14:22 +00:00
andvar b117086304 fix some typos and grammar in comments. 2022-08-07 10:12:19 +00:00
andvar 6478b40555 s/blity/bility/ in various words, mainly in comments. 2022-08-06 18:26:41 +00:00
kre 52acc68675 Provide _GNU_SOURCE for t_clone now that is required to make clone()
visible.
2022-08-01 15:48:39 +00:00
andvar 4fe346050d s/fucntion/function/ in comments. 2022-07-26 19:49:32 +00:00
riastradh 9f0a763c4a t_sig_backtrace: Pacify vfork clobber warning with volatile. 2022-07-25 22:43:01 +00:00
riastradh 2edbbc6f32 execinfo(3): Mark sig_backtrace_jump test as xfail.
PR lib/56940
2022-07-25 22:37:37 +00:00
riastradh d14f9f0135 execinfo: Fix mistake in previous: match `the_loop*' as prefix.
Now that there are two functions we need to catch either one.
2022-07-25 11:02:41 +00:00
riastradh 03353bf482 execinfo: Test stack traces through null pointer jump too. 2022-07-25 10:38:17 +00:00
kre fa7d65a3b6 Add ATF tests for realpath(1)
Note that realpath can act differently for root than for other users
(where an ordinary user will see EACCESS root just barrels right through).

The tests adapt themselves, when run as root, less error cases can be
tested than when run as some other user.
2022-07-21 09:52:48 +00:00
thorpej 75d451f371 Make kqueue event status for vnodes shareable, and for stacked file systems
like nullfs, make the upper vnode share that status with the lower vnode.

And, lo, NetBSD 9.99.99.

Fixes PR kern/56713.
2022-07-18 04:30:30 +00:00
rillig d39a56301d lint: add more details to message about pointer alignment
The previous message 'may cause alignment problem' was not detailed
enough to be actionable, it didn't give the necessary insight to why
lint was complaining at all.

The new message 'increases alignment from 1 to 4' or 'from 2 to 8'
describes the potentially problematic conversion, and together with the
involved type names, it allows an informed decision about whether lint's
warning is warranted or not.

In a typical NetBSD build, this warning is in the top 10.  The number of
these warnings depends on the architecture, it is typically between 800
and 1600.
2022-07-16 22:36:06 +00:00
rillig 238d676f52 lint: fix edge cases in the query for redundant cast before assignment
Casting from and to _Bool is only allowed outside strict bool mode.
Outside strict bool mode, _Bool is an integer type, therefore return
early if any of the operands has type _Bool.  In strict bool mode, even
casting from _Bool to _Bool is not allowed, as it is not needed in
practice.

Handle _Complex types before real floating-point types.  Return early
for _Complex types, as these are floating-point types as well.

For pointer casts, not only flag casts to or from 'pointer to void', but
also casts between the same types.

In debug mode, when constructing the type '_Complex float', the type
name of '_Complex' occurs in the debug log.  Outside of debug mode,
printing this type name is an error since this type keyword only occurs
internally, when constructing a type.  At that point, it is not supposed
to occur in any user-visible message.
2022-07-08 21:19:06 +00:00
rillig 9db688f9b4 lint: fix query for redundant cast before assignment
Previously, 'i = (int)dbl' was marked as redundant, even though it
performs a value conversion.
2022-07-08 20:27:36 +00:00
rillig 881bc41253 tests/lint: document why in ic_expr, '&' does not need before_conversion 2022-07-07 18:11:29 +00:00
rillig 5158c3886d lint: do not warn about 'may lose accuracy' in safe cases of '%'
The possible values of the expression 'a % b' for unsigned integers lie
between 0 and (b - 1).  For signed integers, it's more complicated, so
ignore them for now.
2022-07-06 22:26:30 +00:00
rillig 41da170b98 tests/lint: test 'may lose accuracy' for '%'
For unsigned integers, the possible range of the result can be narrowed
down by looking at the right operand of the '%'.  Right now, lint
doesn't do this though.
2022-07-06 21:59:06 +00:00
rillig d9029d5695 tests/lint: add test for 'assignment in conditional context' 2022-07-06 21:13:13 +00:00
rillig 715e58e70b lint: add additional queries that are not enabled by default
In the last 18 months, several lint warnings have been made adjusted to
allow common usage patterns.  For example, lint no longer warns about a
constant condition in the statement 'do { ... } while (false)' (message
161), as this pattern is well-known in statement-like macros, making it
unlikely that the 'false' is a mistake.  Another example is casts
between unequal pointer types (message 247) for a few well-known
patterns that are unlikely to be bugs.

Occasionally, it is useful to query the code for patterns or events that
would not justify a warning.  These patterns are modeled as predefined
queries that can be selected individually, in addition to and
independently of the existing warnings and errors.

New queries can be added as needed, in the same way as new warnings.
Queries that are deemed no longer used can be deactivated in the same
way as warnings that are no longer used.

As long as none of the queries is enabled, they produce a minimal
overhead of querying a single global variable.  Computations that are
more expensive than a few machine instructions should be guarded by
any_query_enabled.

https://mail-index.netbsd.org/source-changes-d/2022/06/28/msg013716.html

ok christos@
2022-07-05 22:50:41 +00:00
rillig 1929095001 lint: include the width of bit-fields in the type name 2022-07-03 14:35:54 +00:00
rillig 28cc4da32f tests/lint: test bit shift with large integer types
build_bit_shift converts the right-hand operand to INT or UINT, even
though C11 6.5.7 doesn't say anything about narrowing conversions.

Traditional C says that the operators '<<' and '>>' perform the usual
arithmetic conversions.  This has been dropped in C90.

What lint actually does is something completely different.  In the
operators table in ops.def, the operators '<<' and '>>' are not marked
as performing the usual arithmetic conversions (column 'balance').  This
leaves all conversions to 'build_bit_shift', which converts the
right-hand side to INT or UINT.  There is no obvious reason for this
conversion, as the bounds checks need to be performed no matter whether
the type is INT or UINT128.
2022-07-02 09:48:18 +00:00
rillig 8d59a8c8e2 lint: add quotes around operator in message 138, remove message 240
Message 138 doesn't occur in practice, it was the last one that was
missing the quotes around the placeholder.

Message 240 was also missing the quotes, but it was not reachable. There
was also no apparent benefit in warning about 'assignment of different
structures' when the message about 'assignment type mismatch' serves the
same purpose.
2022-07-01 20:53:13 +00:00
rillig a01cec450c tests/lint: add tests for accessing incomplete types 2022-07-01 20:35:18 +00:00
rillig 87f7a17b45 lint: do not warn about pointer casts to array types
If the (recursive) element type of the array is compatible, that's good
enough.  Even after the previous commits, this warning is the one that
occurs most in a standard NetBSD build, and it is generally ignored.
For now, focus on reducing the number of false positives to an
acceptable level.
2022-06-24 21:22:11 +00:00
rillig 79312644ef tests/lint: demonstrate another warning about pointer casts 2022-06-24 21:02:10 +00:00
rillig b2f8c42322 lint: allow pointer cast between compatible structs
Lint already allowed pointer casts from 'struct counter' to 'struct
counter_impl'.  Now it also allows the other direction.
2022-06-24 20:44:53 +00:00
rillig 66b8d73a0e tests/lint: demonstrate warning for cast between compatible structs 2022-06-24 20:32:12 +00:00
rillig 0877aaac93 lint: do not warn about pointer cast between sockaddr variants 2022-06-24 20:16:21 +00:00
rillig 82c8f75d09 tests/lint: demonstrate pointer casts between sockaddr variants 2022-06-24 20:02:58 +00:00
rillig 28d4550ae5 lint: allow pointer cast from char to struct/union 2022-06-24 19:27:43 +00:00
rillig e3e24cb044 tests/lint: demonstrate dubious warnings for pointer casts
Casting a 'pointer to char' to a 'pointer to anything else' is already
allowed, except for 'pointer to struct/union'.  The cause for this
inconsistency is the wrong order of checks in
'should_warn_about_pointer_cast'.
2022-06-24 19:20:39 +00:00
wiz 3a171c57ac test: fix typo and improve wording 2022-06-22 21:11:41 +00:00
rillig 40a9b8fdca lint: add quotes around placeholders for the remaining messages
Reword some of the messages slightly, exchanging brevity for clarity.

Message 138 is kept as-is, as it is not yet covered by any tests.

Message 240 is kep as-is, as it is unreachable.
2022-06-22 19:23:17 +00:00
rillig 6d6723969c lint: add quotes and details to some more messages 2022-06-21 21:18:30 +00:00