13628 Commits

Author SHA1 Message Date
Mark Vitale
b500a76a06 libadmin: allow tests to skip authentication setup
src/libadmin/test/afscp is a testbed with subcommands to test many
libadmin functions.  Almost all of these subcommands call
SetupCommonArgs to add authentication specification arguments (e.g.
-noauth, -cell <cell>, etc).  These common args are checked in
MyBeforeProc to obtain authentication before processing the actual test
subcommand.

However, some afscp subcommands shouldn't need any authentication setup,
for example:
  UtilErrorTranslate -error <code>
  UtilNameToAddress -host <hostname>

In preparation for a future commit, modify MyBeforeProc to skip
authentication setup for subcommands that haven't called SetupCommonArgs
to define authentication options.

Change-Id: I3d6be062c8264ece8eb27c3b2b72c8c45aacae56
Reviewed-on: https://gerrit.openafs.org/14646
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
2022-02-21 20:42:27 -05:00
Mark Vitale
6163ebf345 remove vestigial reference to 'sia'
Commit 21006bb844a3 oops-sias-dead-20080906 removed references to 'sia'
from the tree, but overlooked the reference in the clean2 rule.  This
results in a harmless error from 'make clean', or any target with
'clean' as a dependency:

  /bin/sh: line 0: cd: sia: No such file or directory
  make[1]: [clean2] Error 1 (ignored)

Remove this last reference to eliminate the error.

Change-Id: Ic2827998e3b272acc7714238d0755c5ec2ad2b95
Reviewed-on: https://gerrit.openafs.org/14890
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2022-02-21 20:40:03 -05:00
Cheyenne Wills
b5e0fb0c88 doc: Update INSTALL w/info on overriding dirpaths
Fix a typo in INSTALL for 'afslogsdir'.

Add a note with information that it is possible to override the
directory paths via environment variables.

The added documentation is targeting distro maintainers so they are
aware that the directory paths can be configured without patching.

Change-Id: Ia94d8525db798fe01866126f1f315499296717c9
Reviewed-on: https://gerrit.openafs.org/14888
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Ralf Brunckhorst <rbrunckhorst@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2022-02-13 13:51:48 -05:00
Andrew Deason
17b16cb398 UKERNEL: Remove socket -> usr_socket redirection
Currently, src/afs/UKERNEL/sysincludes.h #defines 'socket' to
'usr_socket', in order for 'struct socket' declarations to use struct
usr_socket. Redefining a simple word/function like 'socket' can easily
cause issues, and currently makes it difficult to introduce libroken
callers in UKERNEL code. There are already several instances of
'#undef socket' in the tree for UKERNEL, suggesting that this wasn't a
good idea to start with.

Fortunately, this redefinition of 'socket' in UKERNEL seems
unnecessary, since the only place 'struct usr_socket' is actually
deferenced is inside src/rx/UKERNEL/rx_knet.c. So we can treat 'struct
usr_socket' as a struct definition that's just internal to rx_knet.c,
and no other code even needs to know about the struct, or think that
it's equivalent to 'struct socket'.

Most code in rx_knet.c already explicitly casts between 'struct
socket' and 'struct usr_socket'. The only exception is rxi_Recvmsg
starting in commits near 27c42be1 (ukernel-rx-knet-deref-20060126),
but this is easily fixed by adding an additional explicit cast.

Change-Id: I4a2af32b33a86a10750d569ac3c91d0c79f49459
Reviewed-on: https://gerrit.openafs.org/14887
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
2022-01-30 22:32:53 -05:00
Cheyenne Wills
6bdfa97673 Linux-5.17: Kernel build uses -Wcast-function-type
The linux 5.17 commit:
  "Makefile: Enable -Wcast-function-type" (552a23a0)
added the -Wcast-function-type compiler flag for kernel module builds.

This change catches a type mismatch in the external files obtained from
heimdal: hcrypto/evp.c and hcrypto/evp-algs.c and produces the following
type of compile time error messages.

  src/libafs/MODLOAD-.../evp.c: In function ‘hc_EVP_md_null’:
  src/libafs/MODLOAD-.../evp.c:501:2: error: cast between incompatible
      function types from ‘void (*)(void *)’ to ‘int (*)(EVP_MD_CTX *)’
          {aka ‘int (*)(struct hc_EVP_MD_CTX *)’}
          [-Werror=cast-function-type]
  501 |  (hc_evp_md_init)null_Init,
      |  ^

Use AX_APPEND_COMPILE_FLAGS to create a CFLAGS_NOCAST_FUNCTION_TYPE
macro to disable this warning and update the CFLAGS for these 2 files
for the Linux libafs build.

Update the CODING documentation to add the new exceptions.  In addition
add a brief description on how to set up autoconf to add a new build
macro to suppress compiler warnings.

Note: upstream heimdal has committed a fix for this in:

   hcrypto: Fix return type for null_Init, null_Update and null_Final
   (fc4b3ce49b)

Change-Id: I05b716867016a33ca02a791ed6bc5a7d846de608
Reviewed-on: https://gerrit.openafs.org/14881
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
2022-01-29 15:34:47 -05:00
Andrew Deason
738a6487ad afs: Organize setpag() declarations better
The current declarations for setpag() are a mess (not to be confused
with many other setpag functions, like afs_setpag()), accumulated
across various commits over time. Shuffle the #ifdef logic around, so
this becomes a much more straightforward #ifdef ladder, with one
declaration per conditional. And move the LINUX declaration to be next
to all of the others (even the LINUX setpag() is declared in
osi_groups.c, not osi_misc.c, so it's in the wrong spot anyway).

The resulting #ifdef logic should be identical to the original code,
but is now easier to follow. For the BSDs, it may look like we have
changed the conditional for the case of "XBSD && !DFBSD && !FBSD &&
!NBSD", but that's a very roundabout way of saying OBSD (OpenBSD).

Change-Id: I062a2537ccf89b6d2535fe2919ca04ef16a84e4a
Reviewed-on: https://gerrit.openafs.org/14883
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2022-01-29 15:33:58 -05:00
Cheyenne Wills
a651d4db7f Linux-5.17: kernel func complete_and_exit renamed
Handle the Linux kernel function rename made in commit
 "exit: Rename complete_and_exit to kthread_complete_and_exit"
 (cead1855)

Add a new autoconf test for the linux function kthread_complete_and_exit
and if not found use a define to map kthread_complete_and_exit to
complete_and_exit.

Replace calls to complete_and_exit with kthread_complete_and_exit.

Change-Id: If8db2d0abb1de8b08f511e9ff67612ef605cd603
Reviewed-on: https://gerrit.openafs.org/14882
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2022-01-28 23:20:00 -05:00
Cheyenne Wills
92342b099d afs.h: fix out of tree build failures
There are several compiler errors and warnings when building an out of
tree program that includes "afs/afs.h".

 - Errors for unknown type names 'afs_ucred_t' and 'wait_queue_head'
    .../afs/afs.h:1542:16: error: unknown type name ‘afs_ucred_t’
      ... | afs_set_cr_uid(afs_ucred_t *cred, uid_t uid) {
    .../afs/afs.h:1605:5: error: unknown type name ‘wait_queue_head_t’
      ... |     wait_queue_head_t cond;

 - Warnings about declaring structures within missing declarations for
   the structs: osi_File, dcache and afs_FetchOutput
   .../afs/afs.h:1486:36: warning: ‘struct osi_file’ declared inside
        parameter list will not be visible outside of this definition or
        declaration
      ... |     int (*read)(void *rock, struct osi_file *tfile,
                     afs_uint32 offset,

 - Unable to find the file for the include opr/jhash.h

The missing type name 'afs_ucred_t' is due to miss-placed declarations
for some kernel only functions.

The type name 'wait_queue_head' is a data type for Linux kernel modules.

The warnings for the missing declarations are due to either references
to the structures before they are declared, or because they are not
available in any of the other public header files.

To fix the unknown type name afs_ucred_t, relocate the function
declarations that reference 'afs_ucred_t' into the KERNEL only section
(since afs_ucred_t is a kernel specific type).

To fix the unknown type name 'wait_queue_head', relocate the afs_event
structure and the afs_evhasht variable to be within the KERNEL only
section.

To resolve the warnings associated with the structures, simply declare
the structure names before they are referenced.  All references that
are resulting in the warnings are declarations for pointers.

Relocate the include for opr/jhash.h and the define for VCSIZE into the
kernel block.

Change-Id: I4135ff25b76d3221c7779c279ed829000ce31f1c
Reviewed-on: https://gerrit.openafs.org/14857
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2022-01-13 00:28:12 -05:00
Mans Nilsson
7a6192276b Add sysname, files and header entries for FreeBSD 12.3
Created a new sysname "amd64_fbsd_123" in src/config/afs_sysnames.h
and added "param" files with minimal changes:

	modified:   src/config/afs_sysnames.h
	new file:   src/config/param.amd64_fbsd_123.h
	new file:   src/config/param.i386_fbsd_123.h

This mod builds on 12.3 with all tests passing.

Change-Id: Iccf9cfe75362511337b1c09267489d258a5913cb
Reviewed-on: https://gerrit.openafs.org/14860
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-12-29 22:09:35 -05:00
Andrew Deason
dcf8af0b22 tests: Add test keys in afstest_BuildTestConfig
Change afstest_BuildTestConfig to add the local keys into the
generated config dir, unless the info->skipkeys is set. This just
makes afstest_BuildTestConfig a little easier to use for the common
case of generating a fully-usable config dir with usable keys (only
some callers want to skip generating keys in order to test
key-populating functionality).

Change-Id: I1ce9d062ea30c391a93562fc90bc18997de75383
Reviewed-on: https://gerrit.openafs.org/14835
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-12-27 22:46:12 -05:00
Andrew Deason
d5e1428a3b afs: Drop GLOCK for various Rx calls
Most calls into Rx from libafs do so without the AFS_GLOCK, but a few
pieces of code still hold AFS_GLOCK while making some Rx calls. A few
calls into Rx also currently require AFS_GLOCK, but drop AFS_GLOCK
internally, which is somewhat confusing/inconsistent. Calling Rx
functions with AFS_GLOCK held can potentially cause locking/allocation
problems on various platforms, such as FreeBSD where we get WITNESS
warnings about acquiring sleepable Rx locks while holding the
non-sleepable AFS_GLOCK.

Fix a variety of Rx calls from libafs to drop AFS_GLOCK before calling
into Rx. Specifically, this commit handles calls to rxi_GetIFInfo,
rx_InitHost, rx_StartServer, rx_ServerProc, rx_GetConnection,
rx_DestroyConnection/rx_PutConnection, and
rx_SetConnSecondsUntilNatPing.

For calls made via afs_start_thread, adjust afs_start_thread to accept
a new argument that says whether to acquire AFS_GLOCK for the relevant
function or not.

For a call to rx_InitHost inside afs_InitSetup, dropping GLOCK makes
it possible for another thread to also enter afs_InitSetup while we're
running, before afs_InitSetup_done is set. To prevent two threads from
running afs_InitSetup in parallel, introduce afs_InitSetup_running
(which is set while afs_InitSetup is running), and simply wait for it
to be cleared if it is set when we enter afs_InitSetup.

This commit does not handle strictly all calls into Rx from libafs,
since many Rx calls don't do anything interesting besides set some
internal variables, and so AFS_GLOCK doesn't really matter for them,
and dropping/reacquiring it around those calls may have performance
impact.

Change-Id: Ib6344f08593182ad0f812ea42eb8c91d8f082356
Reviewed-on: https://gerrit.openafs.org/14184
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
2021-12-09 13:55:11 -05:00
Cheyenne Wills
2a659ba160 autoconf: Remove/update obsolete autoconf macros
Autoconf 2.70 (released in 2020-12) produces warning messages about
obsolete constructs by default.

Running regen.sh with autoconf 2.70 installed produces the following
warnings:

..
 configure.ac:7: warning: The macro `AC_CONFIG_HEADER' is obsolete.
 configure.ac:21: warning: AC_PROG_LEX without either yywrap or noyywrap
   is obsolete
 configure.ac:21: warning: The macro `AC_HEADER_STDC' is obsolete.
 configure.ac:21: warning: The macro `AC_HEADER_TIME' is obsolete.
..

Replace AC_CONFIG_HEADER with AC_CONFIG_HEADERS

Add the noyywrap parameter to AC_PROG_LEX.  Use the noyywrap option
since we already provide a yywrap function in the .l sources.

Remove AC_HEADER_STDC.  There are no references to the the autoconf
variable set by this macro.  This macro was marked as obsolete prior to
autoconf 2.64 with the following note:
 "This macro is obsolescent, as current systems have conforming header
 files. New programs need not use this macro."

AC_HEADER_TIME was marked as obsolete prior to autoconf 2.64 with the
following note:
 "This macro is obsolescent, as current systems can include both files
  when they exist. New programs need not use this macro."

The only reference that requires AC_HEADER_TIME is within the external
roken code pulled from heimdal. Compiles that use the external upstream
heimdal packages result in a build error if TIME_WITH_SYS_TIME is not
defined:
  building src/crypto/hcrypto
    src/external/heimdal/hcrypto/camellia.c
      include/roken.h:803:58: error: ‘struct tm’ declared inside

Update autoheader.m4 so a define for TIME_WITH_SYS_TIME is created. This
avoids modifying the external heimdal/roken code.

Change-Id: If4d6c0650aac617f535b35f81994b54a3b8ac021
Reviewed-on: https://gerrit.openafs.org/14838
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-12-02 11:57:47 -05:00
Cheyenne Wills
3daa6e9733 LINUX-5.16: Use linux/stdarg.h if available
Global use of the compiler option '-isystem' was removed from the top
level Makefile with Linux commit ('isystem: delete global -isystem
compile option' 04e85bbf7). This results with an error due to not
finding "stdarg.h" when building the openafs kernel module.

 .../src/rx/rx_kcommon.h:143:12: fatal error: stdarg.h: No such file or
                                 directory
   143 | #  include "stdarg.h"
       |            ^~~~~~~~~~

Linux-5.15, introduced a copy of stdarg.h as 'linux/stdarg.h' in commit
('isystem: ship and use stdarg.h' c0891ac15)

Add a test for the linux/stdarg.h include file and if available, use
"linux/stdarg.h" instead of "stdarg.h" within the Linux kernel module.

Change-Id: I5215182c8240034bd739688a88a9410b74f93c8f
Reviewed-on: https://gerrit.openafs.org/14844
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-11-16 20:49:41 -05:00
Benjamin Kaduk
03e208df27 prdb.txt: correct fixed header length
It is decimal 64, not hex 64.

Change-Id: Iee51f4536e8e811bd6ba7e2b86bdde5183227928
Reviewed-on: https://gerrit.openafs.org/14824
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-28 00:56:26 -04:00
Andrew Deason
6f5f13795a tests: Check for vlserver startup
Currently, afstest_StartVLServer waits for a fixed amount of time (5
seconds) for the vlserver to startup. This means each test that runs a
vlserver takes at least 5 seconds, which adds up very quickly when new
tests are added for vlserver functionality.

Instead of waiting 5 seconds each time, change afstest_StartVLServer
to check if the vlserver has started up, and to wait a much shorter
time if it hasn't finished starting up yet. Specifically, wait until
the "Starting AFS vlserver" message appears in VLLog, and the
UBIK_RECHAVEDB recovery state bit is set. This allows vlserver-based
tests to run much more quickly.

Change-Id: I74015670a301980e6d89b3149ed9f2a6c1a40523
Reviewed-on: https://gerrit.openafs.org/14804
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-27 01:07:05 -04:00
Andrew Deason
c3df91f303 tests: Introduce afstest_MyHostAddr
Several places resolve the local hostname into an IP address.
Consolidate these into a single function (gethostaddr), and add the
function afstest_MyHostAddr, which caches the IP and bails if we can't
resolve our hostname.

Change-Id: I7f71cd136796e4395c639eed8dd8eb19a7b9beec
Reviewed-on: https://gerrit.openafs.org/14802
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-27 01:06:33 -04:00
Mark Vitale
f29ca90311 afs: record afs_CacheTruncateDaemon stats indirectly
In preparation for a future commit, record the CTD_stats through a
pointer.

No functional change is incurred by this commit.

Change-Id: Id0cb97daf06535bad2d14be19bc8d957d6816808
Reviewed-on: https://gerrit.openafs.org/14199
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
2021-10-22 09:21:08 -04:00
Mark Vitale
ee49a57bb4 afs: export internal stats for afs_CacheTruncateDaemon
In preparation for a future commit, redefine CTD_stats so they can be
reported externally.  While here, move and rename the struct.

While here, also remove an old comment concerning AIX.

No functional change is incurred by this commit.

Change-Id: If68e44f9dfae5a227d3a24f9fe34932ead1972d1
Reviewed-on: https://gerrit.openafs.org/14198
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
2021-10-22 01:08:19 -04:00
Mark Vitale
e59307c14d afs: consolidate disk block calculations
Similar code is used in several places to calculate the number of 1KiBi
blocks required for a cache chunk, rounded up to the nearest
afs_fsfragsize.  Coalesce these into a single inline function,
afs_round_to_fsfragsize.

No functional change should be incurred by this commit.

Change-Id: I1f58ad28426b786fc9809df01d409c8137437012
Reviewed-on: https://gerrit.openafs.org/14227
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
2021-10-22 00:24:24 -04:00
Mark Vitale
10c5ba12ac Add static assert for size of osi_timeval32_t
OpenAFS code requires osi_timeval32_t to have 32-bit sizes for members
tv_sec and tv_usec - a total of 8 octets.  One symptom of a
misdefinition may be incorrect operation of xstat_cm_test, which relies
on wire representations of time being 8 bytes on both the client and
server side.

In order to prevent incorrect sizes of osi_timeval32_t, add a static
assert.

Change-Id: Iff487da792aec5aae5e32b2d3409d8639a7ea51a
Reviewed-on: https://gerrit.openafs.org/14195
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
2021-10-21 14:15:35 -04:00
Andrew Deason
fd636c8f20 FBSD: Drop GLOCK when grabbing vnode locks
In a few places, we try to vn_lock() or VOP_LOCK() while holding
AFS_GLOCK (or do something like vrele(), which internally acquires the
vnode lock). This is against the FBSD locking rules, since our
AFS_GLOCK is a non-sleepable 'struct mtx' lock, and vnode locks are
sleepable lockmgr locks.

So, drop AFS_GLOCK while acquiring vnode locks.

Change-Id: I0ca449bb6398aa8ededd5bb67d56a7d3f13688f0
Reviewed-on: https://gerrit.openafs.org/14182
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
2021-10-21 12:43:47 -04:00
Cheyenne Wills
489cfb587a Remove kdump
Remove the obsolete kdump debugging tool from the tree.  Remove and
clean up the preprocessor tests associated with KDUMP, KDUMP_RX_LOCK and
KDUMP_KERNEL.  Clean up the autoconf and Makefiles to remove kdump and
the associated autoconf and Makefile vars XLIBELFA and XLIBKVM.

The kdump utility has not been well maintained; for some platforms it
fails to build (e.g. Solaris 11).  For Linux, the makefile does not
even try to compile the kdump source but instead creates the kdump file
via touch.

The intended functionality of kdump has been replaced by various kernel
debugging tools, such as dtrace or systemtap.

Change-Id: I23fd82f2b96ba58d1b431af76fdf0afe7d7274b9
Reviewed-on: https://gerrit.openafs.org/14623
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-21 12:32:23 -04:00
Andrew Deason
0abef5765c FBSD: use sx(9) locks for rx afs_kmutex_t
On FBSD, afs_kmutex_t is defined as a struct mtx, which is a
non-sleepable lock. If we hold one of these locks and then try to
acquire a sleepable lock, there is the potential for deadlock, and
WITNESS complains.

One way this is a problem is that we acquire IFNET_RLOCK in
rxi_GetIFInfo(), which is a sleepable lock. We enter this function
via rxi_FindPeer -> rxi_InitPeerParams, which is encountered while
holding a variety of different Rx locks in different situations, such
as rx_peerHashTable_lock and rx_connHashTable_lock.

Another way this is a problem is that we allocate memory in a variety
of situations whole holding various Rx locks. Currently many of these
are sleepable allocations (which could cause deadlocks); we could
avoid that if they were converted to non-sleepable allocations, but
then the allocations may fail and we'd need to adjust all of the
relevant code paths to accommodate.

To avoid these issues, define Rx's afs_kmutex_t locks to sx(9) locks,
which are sleepable. Drop the use of MTX_DUPOK/SX_DUPOK during lock
init, since we shouldn't be acquiring duplicate locks.

This does not appear to introduce any new issues, except where we
acquire Rx locks while holding the libafs AFS_GLOCK, which we probably
shouldn't be doing and is fixed in subsequent commits. Note that other
platforms also tend to use sleepable locks for afs_kmutex_t: for
example, on LINUX, we use struct mutex (which is sleepable).

Change-Id: I78ede8eb6ba8935d0082925c5475c42260eb7d59
Reviewed-on: https://gerrit.openafs.org/14183
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-21 12:27:03 -04:00
Andrew Deason
e3a87cdcf7 ubik: Skip sleep on first pass in urecovery loop
When running a dbserver without any remote sites, we become the sync
site immediately, since there aren't any other sites so we don't need
to do any processing of votes. The ubik database can thus be accessed
immediately, except we cannot start ubik write transactions right
away, since UBIK_RECHAVEDB will not be set, causing
urecovery_AllBetter() to fail.

UBIK_RECHAVEDB is not set immediately, because urecovery_Interact
sleeps 4 seconds at the beginning of its loop, so no recovery flags
will be set for the first 4 seconds during startup. This makes it
impossible to start any ubik write transactions for the first 4
seconds, even if we're the only site. That may not be a significant
amount of time for a user (since a dbserver daemon doesn't startup too
frequently), but this can cause huge delays for automated testing of
dbservers.

To get rid of this unnecessary delay, just skip this delay the first
time we go through the urecovery_Interact loop.

Change-Id: Ie6653b7b742dcf37798a6bf340b29c283ac3bc4c
Reviewed-on: https://gerrit.openafs.org/14803
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-14 12:05:11 -04:00
Benjamin Kaduk
6267afb52e prdb_check: fix -pheader output
This is prdb_check, so we will print the PRDB header, not the
KADB header.

Change-Id: Id956400794ce866875c1772791301122cc4e1413
Reviewed-on: https://gerrit.openafs.org/14827
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-13 23:07:38 -04:00
Cheyenne Wills
ba485a13e9 LINUX 5.14: explicitly set set_page_dirty to default
Linux 5.14 commit: 'mm: require ->set_page_dirty to be explicitly wired
up' (0af573780b0b13) removed calling __set_page_dirty_buffers when the
address_space_operations structure member set_page_dirty was NULL.

A kernel RIP error can occur when the set_page_dirty operation is
requested. (Reproducible by running 'iozone -B -a')

Update the definition for afs_file_aops to explicitly set the
'set_page_dirty' member to '__set_page_dirty_buffers'.

There are no functional changes, since this commit is using the same
function that the Linux kernel was using if set_page_dirty had been
NULL.

Problem originally reported by "Andrej Filipcic"
<andrej.filipcic@ijs.si> in the openafs-info mailing list.  The Linux
5.14 commit causing the openafs failure was identified by "Michael Laß"
<lass@mail.upb.de> also on in the openafs-info mailing list.

Note: The declaration for the function '__set_page_dirty_buffers' was
moved from linux/mm.h into linux/buffer_head.h in Linux 2.6.19.  Since
this is close to the minimum supported Linux version 2.6.18, we are not
introducing an additional autoconf test to determine which header file
the declaration for __set_page_dirty_buffers resides in.

Change-Id: I8f2a00e374635ab1aa69d6eaef8cf97bb449d089
Reviewed-on: https://gerrit.openafs.org/14826
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Tested-by: Michael Laß <lass@mail.uni-paderborn.de>
Reviewed-by: Michael Laß <lass@mail.uni-paderborn.de>
Tested-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Ralf Brunckhorst <rbrunckhorst@sinenomine.net>
Tested-by: Ralf Brunckhorst <rbrunckhorst@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-12 14:57:05 -04:00
Jeffrey Altman
8f1eba056f CVE-2018-7168 RXAFS_StoreACL deprecate 134 introduce 164
There exist in the wild AFS3 clients that improperly construct access
control lists which are then stored to directories via RXAFS_StoreACL
(opcode 134).  These clients add negative access control entries (if any)
to the normal rights list.

As there is no method by which a fileserver can determine that the
ACL is improperly constructed, the only method to defend the storage of
broken ACLs is to identify clients that are known to properly construct
ACLs by introducing a new RXAFS_StoreACL opcode (164).

This change:

 * Renames RXAFS opcode 134 to RXAFS_OldStoreACL

 * Introduces RXAFS opcode 164 as RXAFS_StoreACL

 * Implements SRXAFS_OldStoreACL and SRXAFS_StoreACL in the fileserver
   via a common_StoreACL() function that accepts the executed opcode
   as input.

 * To avoid breaking changes in stable release branches,
   SRXAFS_OldStoreACL will still be allowed by default, with an option
   to cause it to be failed by default with error EPERM/UAEPERM.
   A follow-up commit will cause SRXAFS_OldStoreACL to fail by default
   on the master branch.

 * When opcode 134 is called, the a FileLog entry will be generated
   at log level 0 instead of 1 and the entry will contain the string
   "CVE-2018-7168".

 * Modifies the format of the ACL logged to the FileLog and the audit
   stream.  Previously the AFSOpaque format was used directly.  The
   problem with this format is that it uses newlines as the ACE
   separator.  Since the FileLog and file audit log is intended to
   be one line per log entry, the newlines break the file formats.
   This change replaces the newlines with spaces for display purposes
   unless the process is unable to allocate the additional memory.

 * Introduces a new fileserver command line switch -cve-2018-7168-enforce
   which when specified causes SRXAFS_OldStoreACL RPCs to be failed.

[kaduk@mit.edu: switch en/disable-by-default behavior and fix argument parsing]

Change-Id: Ic92ef45314d75fbc2b8ff574223fab2d398a1d60
FIXES: 134485
Reviewed-on: https://gerrit.openafs.org/12942
Reviewed-by: Jeffrey Altman <jaltman@auristor.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-08 16:15:55 -04:00
Andrew Deason
d731d3c5bc tests: Add existing-database test for pt_util
Our current tests for pt_util use pt_util to generate a prdb, and then
check the output of pt_util against that created database. Add a new
test that runs pt_util against an existing database (with the same
test data), to make sure that pt_util is still using the same db
format.

Change-Id: I4dbe7f3b5080ee6ff1f9509992b5686fc8381da0
Reviewed-on: https://gerrit.openafs.org/14801
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-08 00:05:02 -04:00
Cheyenne Wills
21df433134 rx: Cleanup rx.h
Fix up indentation and white space within preprocessor statements.

Remove multiple blank lines

Fix #endif comments so they match the #if

Split long #define lines
  RX_PACKET_TYPES
  rx_MaxUserDatasize,
  RXS_OP
  RXS_SetConfiguration

Note, this commit does not refactor any preprocessor statements.

Change-Id: I327e9588e96bba9d768ccf345650aced7e824328
Reviewed-on: https://gerrit.openafs.org/14629
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-07 22:12:37 -04:00
Andrew Deason
e07768aaf7 tests: Introduce afstest.pm
Create a perl module for some generic common code for our tests
written in perl: afstest.pm. With this commit, the module just
contains a couple of functions to calculate paths in our src and obj
trees (src_path(), obj_path()), analogous to afstest_src_path and
afstest_obj_path in our C helper library, libafstest_common.la.

Convert all existing perl test code that uses C_TAP_SOURCE/C_TAP_BUILD
to use these new functions.

Change-Id: I5e4d45e3d2d59449bbfc426476cb29b710c73bc1
Reviewed-on: https://gerrit.openafs.org/14800
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-03 17:55:18 -04:00
Marcio Barbosa
83d947c150 fs: add option to evaluate symlink or mtpt
Currently, several fs subcommands for Windows offer an option (-literal)
to evaluate symlink / mount point rather than the object it refers to.
Provide the same option on Unix for fs_getfid.

Change-Id: I55ab5f96d5b9e63efbe7e938647edba05a1787ed
Reviewed-on: https://gerrit.openafs.org/14542
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-03 14:23:06 -04:00
Andrew Deason
a9c1939eeb FBSD: Use GENERIC kernel headers by default
Currently, if --with-bsd-kernel-build is not specified during
configure, we do not set KERNBUILDDIR during the libafs build at all.
This means that we do not use an opt_global.h during the build.

For the GENERIC kernel, in the past this has worked well enough to
produce a working kernel module, but with FreeBSD 12, the GENERIC
kernel turns on the VIMAGE option by default. If our kernel module is
built without VIMAGE defined, our kernel module cannot be loaded into
GENERIC, since VIMAGE changes the definitions of some symbols that we
use (for example, trying to load such a libafs fails with the message
"link_elf_obj: symbol in_ifaddrhead undefined").

To allow the build to work by default for GENERIC kernels, without
needing any additional configure flags, change the libafs Makefile to
use the headers for the GENERIC kernel if no kernel build dir is
given. To do this, we create a directory in our build tree and
generate the opt_*.h headers in there (using config(8)), and specify
that directory as the kernel build dir.

This approach only works for GENERIC kernels, of course, but that is
the most common scenario. Users that want to build for a custom kernel
configuration still need to specify the actual kernel build dir with
--with-bsd-kernel-build.

Change-Id: If716d3f8ded9596d8e5e98bf2e58888921fc5f7f
Reviewed-on: https://gerrit.openafs.org/14001
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-03 01:59:30 -04:00
Andrew Deason
239be1a805 afs: Call afs_FindVCache with DO_STATS, not 1
Several callers pass the bare literal 1 to afs_FindVCache, instead of
the named constant DO_STATS. Use the constant, for clarity.

Change-Id: I0c70ee17f48c773dcb3f4d42ec106f440c5bed2c
Reviewed-on: https://gerrit.openafs.org/14823
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-03 01:53:21 -04:00
Andrew Deason
e0c288416d IRIX: Remove pre-65 code
Commit d1923139 (irix kill efs and start pruning pre-65) removed all
files that defined AFS_SGI64_ENV and earlier, but didn't remove that
code that depended on those defines. In addition, there has been code
in the tree that checks for AFS_SGI53_ENV since OpenAFS 1.0, but
nothing has ever defined Irix 5.3 support in OpenAFS.

Remove all of this obsolete code. Change all references to
AFS_SGIXX_ENV to AFS_SGI_ENV, and assume AFS_SGI_ENV is defined in all
IRIX dirs. Consolidate some of the resulting ifdef logic
appropriately.

Change-Id: I9dd426296e04801980b805a5e195063762b23189
Reviewed-on: https://gerrit.openafs.org/14230
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-03 01:25:21 -04:00
Andrew Deason
1c3d360de6 afs: Remove 'retry' arg from afs_FindVCache
Since OpenAFS 1.0, afs_FindVCache has had an optional 'retry' output
arg. The relevant functionality appears to have been specific to Irix
versions before 5.3, but even OpenAFS 1.0 only had param.h files and
general build logic for Irix 6.2 and later.

With commit 13e44b2b (afs: Refactor osi_vnhold/AFS_FAST_HOLD), the
unused 'retry' argument has now been removed from the lower-level
osi_vnhold function, so now remove it from afs_FindVCache and related
comments, and remove the associated logic to handle a non-zero
'retry'.

Change-Id: I4464347bf6e0a57f8babbcdcdf5283e52532f687
Reviewed-on: https://gerrit.openafs.org/14231
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-02 21:32:12 -04:00
Michael Meffie
a79d3ab92d bos: Improve string safety
To avoid potential string overflows and allow for larger strings in the
future, convert to safe string functions and remove fixed length stack
allocated strings in the bos client.

Add string truncation checks to the date format helper function.

Change-Id: Icf73b970d2c5d22fc6d3c8201498eff74e104812
Reviewed-on: https://gerrit.openafs.org/14765
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-09-30 01:22:42 -04:00
Mark Vitale
5c829c9c56 afs: remove dead code afs_SetCheckServerNATmode
afs_SetCheckServerNATmode was introduced by f86af4af2600
'nat-mode-20060330', an early implementation of cache manager
disconnected mode.

It was first used in d335c636e25d 'discon-20060714'.

The last caller was removed by 99c1e0beb1b
'disconnected-merge-conflict-20080630'.

Remove the dead code.  While here, also remove an incorrect comment on
the default probe interval value.

No functional change is incurred by this commit.

Change-Id: I8b6a9d052d011ad0e7d0d5bd0a816d44a497b697
Reviewed-on: https://gerrit.openafs.org/14812
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
2021-09-29 16:45:30 -04:00
Mark Vitale
4d0c8b265d afs: eliminate INSTRUMENT_LOCKS
Since the original IBM code import, there have been two versions of the
lock macros: one with INSTRUMENT_LOCKS (the default) and one without.
Only the former is ever enabled.  Therefore, remove the unused latter
versions, and all INSTRUMENT_LOCKS conditional logic.

No functional change is incurred by this commit.

Change-Id: I154cd07e81ce7e9a2cc1bb4f0f93615de921e199
Reviewed-on: https://gerrit.openafs.org/14716
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
2021-09-29 16:45:16 -04:00
Mark Vitale
9726ee3226 afs: remove lock dead code
Since OpenAFS 1.0, LockWait has been commented out, and the following
routines have been unreferenced:
- ObtainLock
- ReleaseLock
- afs_osi_SleepR
- afs_osi_SleepW
- afs_osi_SleepS

Remove them from the code and comments.

No functional change is incurred by this commit.

Change-Id: I480d023282878243f9a92f432d7bbec7028af70c
Reviewed-on: https://gerrit.openafs.org/14407
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-09-29 01:29:41 -04:00
Andrew Deason
d8040104f7 tests: Use real tempfile in pt_util-t
Use a real call to File::Temp::tempfile to generate our temporary
filename, instead of creating a somewhat predictable filename based on
our pid.

Change-Id: Icb585c04e088b1fa37dffb6d92fc41cdb14874c7
Reviewed-on: https://gerrit.openafs.org/14799
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-09-19 01:42:47 -04:00
Andrew Deason
1bf2281ecf FBSD: Invalidate pages after non-VM write
Our VOP_WRITE implementation causes the given data to be written to
the libafs cache, and potentially to the fileserver, but does not
update pages mapped to our vnode. This can cause file data to appear
out-of-date if otherwise valid pages exist for that range.

As a practical example of this, when running 'make buildworld' in
/afs, we run:

    cc -nostdlib -Wl,-dc -r -o ipf.lo ipf_stub.o [...]
    crunchide -k _crunched_ipf_stub ipf.lo

The first 'cc' command generates ipf.lo by writing to an mmap'd
region, and the second 'crunchide' command rewrites that file using
write() syscalls.

Afterwards, anything that reads from ipf.lo using mmap'd memory will
see the ipf.lo that 'cc' generated; anything that reads using read()
syscalls will see the updated version from 'crunchide'. And of course
if the pages are evicted for any other reason (such as memory
pressure), everything will see the updated version from 'crunchide'.

The eventual error seen during 'make buildworld' involves duplicate
symbols during linking, since 'crunchide' modifies most symbols to be
hidden. For example:

    cc [...] -static -o rescue rescue.o cat.lo [...] ipf.lo [...]
    ld: error: duplicate symbol: main
    >>> defined at rescue.c
    >>>            rescue.o:(main)
    >>> defined at count4bits.c
    >>>            ipf.lo:(.text+0x10)

    ld: error: duplicate symbol: main
    >>> defined at rescue.c
    >>>            rescue.o:(main)
    >>> defined at trace.c
    >>>            routed.lo:(.text+0x3DE0)
    [...]

To fix this, call vn_pages_remove() to invalidate the pages in the
given range after the write has gone through (successfully or not, in
case of partial writes or other edge cases). We don't do this lower in
afs_write(), since that is also called from our VOP_PUTPAGES()
implementation, and we'd be invalidating pages that we were just given
to write out.

Change-Id: I67708ae994da4a4c26edf32e545606a5238da4d0
Reviewed-on: https://gerrit.openafs.org/14166
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-09-18 21:41:21 -04:00
Michael Meffie
494ec08cd0 vlserver: Use bounded string copy in FindByName()
Although the volname string passed to FindByName() is currently always
limited 65 characters (including the terminating nul), to be on the safe
side, use the bounded strlcpy() function when coping the volname to the
temporary tname local variable to avoid the possibility of overwriting
the stack with an unbounded strcpy().

Change-Id: I12a8ca2901147c7dd88e63339d0d11c3c89bf94a
Reviewed-on: https://gerrit.openafs.org/14763
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-09-17 01:39:54 -04:00
Andrew Deason
fd22b17208 rxgen: Generate default switch arm for void
When defining an xdr union with a 'default' arm, rxgen generates xdr
routines like this:

    bool_t
    xdr_myunion(...)
    {
        switch (objp->op) {
        case FOO:
            xdr_foo(...);
            break;

        default:
            xdr_default(...);
            break;
        }
    }

However, if the default arm of the union is just 'void;', we just
don't generate a 'default:' arm in the switch statment in the
generated routines. If there are enum values that are not explicitly
specified, and are handled by the default arm, this generates a
compiler warning (which breaks the build for --enable-checking):

    foo_int.xdr.c:80:2 error: enumeration value 'BAR' not handled in switch [-Werror=switch]
    switch (objp->op) {

To avoid this, change rxgen to always generate a 'default' arm in the
generated switch if there's one specified in the RPC-L. For a void
default, just generate an empty default arm, which avoids the compiler
warning.

Change-Id: I6ac457a4669439ef896b9cad6eb7de2f03068b69
Reviewed-on: https://gerrit.openafs.org/14798
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-09-16 12:45:04 -04:00
Cheyenne Wills
62de4c948c Remove reference to afsinstall from src/README.md
Commit "deorbit afsinstall" (ed15b0d5b3) removed afsinstall from the
source tree, but not did remove where it was referenced in
src/README.md.

Remove the reference to 'afsinstall' from the 'Not Maintained' section
in src/README.md.

Change-Id: Ie5226bf97003c21044759bd5dc2b8efe5d9138c2
Reviewed-on: https://gerrit.openafs.org/14805
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>
2021-09-16 12:38:33 -04:00
Michael Meffie
a7a672cae8 fs: Trim trailing lsmount and flushmount path slashes
Remove trailing slashes from paths given to `fs lsmount` and `fs
flushmount`.  This makes for a more pleasant user experience when shell
tab completion is used to specify the paths.

Thanks to Stephan Wiesand for pointing out this issue.

Change-Id: I756c4d7d9b3fe5cd41e02165caf1d6866a0210e6
Reviewed-on: https://gerrit.openafs.org/14779
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-09-16 12:22:17 -04:00
Cheyenne Wills
22876c8b88 Linux 5.15: Convert osi_Msg macro to a function
With Linux 5.15-prerc1 printk is defined as a macro instead of a
function ("printk: Userspace format indexing support" 33701557)

This change is causing a build failure:

 .../src/rx/rx_kernel.h:62:18: error: ‘printk’ undeclared (first use in
   this function); did you mean ‘_printk’?
   62 | # define osi_Msg printk)(
      |                  ^~~~~~

The definition and use of the osi_Msg and osi_VMsg macros are
unconventional and the C preprocessor is not handling the macro
expansion when printk is itself a macro.

   #define osi_Msg printk)(
   ...
   (osi_Msg "%s", x);

Change osi_Msg to a function, and simply replace osi_VMsg with vprintf
since osi_VMsg is only used at one location within user space code.

osi_Msg is implemented in 2 locations, in rx_kcommon for kernel space
and in rx_user for userspace.

Note: The unconventional definitions of osi_Msg/osi_VMsg was historical
and due to older compilers not supporting variadic macros.  All of
the currently support platforms should now support variadic functions.

Change-Id: I9f015e4929f2c5120e200d2b0378871e8d1375b3
Reviewed-on: https://gerrit.openafs.org/14791
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-09-16 12:11:02 -04:00
Andrew Deason
92222d0231 FBSD: Disable background stores
Currently, when closing a vcache (via afs_close), we write any dirty
data to the net, and we do so via a background daemon if one is
available (for the rarely-used 'fs storebehind' functionality).

However, on FBSD, this breaks the locking rules, since flushing dirty
pages for a vnode requires the vnode to be locked. In the situation
where we are writing via a background daemon, the afs_close() thread
is what holds the vnode lock, but the background thread is the one
that's actually flushing the dirty pages. So the vnode is effectively
locked in this situation, but to the FreeBSD kernel it looks like we
are flushing pages without the vnode lock, and so it complains:

    kernel: KDB: stack backtrace:
    kernel: #0 0xffffffff80bf6557 at kdb_backtrace+0x67
    kernel: #1 0xffffffff80c7a337 at assert_vop_locked+0x77
    kernel: #2 0xffffffff811fc0bb at VOP_PUTPAGES_APV+0x7b
    kernel: #3 0xffffffff80f016bd at vnode_pager_putpages+0x7d
    kernel: #4 0xffffffff80ef424f at vm_pageout_flush+0xff
    kernel: #5 0xffffffff80ee9b39 at vm_object_page_collect_flush+0x239
    kernel: #6 0xffffffff80ee9819 at vm_object_page_clean+0x179
    kernel: #7 0xffffffff828d7181 at osi_VM_StoreAllSegments+0x111
    kernel: #8 0xffffffff82850a3d at afs_StoreAllSegments+0x9d
    kernel: #9 0xffffffff8287b1ce at afs_StoreOnLastReference+0x17e
    kernel: #10 0xffffffff8282dc70 at BStore+0xd0
    kernel: #11 0xffffffff8282d6ec at afs_BackgroundDaemon+0x2cc
    kernel: #12 0xffffffff828c2f2f at afs_syscall_call+0x35f
    kernel: #13 0xffffffff82855963 at afs3_syscall+0x83
    kernel: #14 0xffffffff81074581 at amd64_syscall+0x291
    kernel: #15 0xffffffff8104cde0 at fast_syscall_common+0x101
    kernel: vnode 0xfffff8006974fc58: tag afs, type VREG
    kernel:     usecount 2, writecount 0, refcount 3
    kernel:     flags (VI_ACTIVE)
    kernel:     v_object 0xfffff80023917900 ref 0 pages 171 cleanbuf 0 dirtybuf 0
    kernel:     lock type afs: EXCL by thread 0xfffff800852775e0 (pid 31828, ld.lld, tid 100787)
    kernel: #0 0xffffffff80b81fc2 at lockmgr_lock_fast_path+0x1e2
    kernel: #1 0xffffffff811fa9f6 at VOP_LOCK1_APV+0x96
    kernel: #2 0xffffffff80c8c705 at _vn_lock+0x65
    kernel: #3 0xffffffff80c8c8a3 at vn_close1+0x73
    kernel: #4 0xffffffff80c8b76c at vn_closefile+0x4c
    kernel: #5 0xffffffff80b571ba at _fdrop+0x1a
    kernel: #6 0xffffffff80b5a3cc at closef+0x1ec
    kernel: #7 0xffffffff80b577be at closefp+0x9e
    kernel: #8 0xffffffff81074581 at amd64_syscall+0x291
    kernel: #9 0xffffffff8104cde0 at fast_syscall_common+0x101
    kernel: vc 0xfffffe002b8d4d30 vp 0xfffff8006974fc58 tag afs, fid: 1.536870912.13317022.33596982, opens 1, writers 1
    kernel:   states statd dirty
    kernel: VOP_PUTPAGES: 0xfffff8006974fc58 is not locked but should be

To avoid this, force afs_close() to write dirty data in the same
thread, instead of passing it off to a background daemon.

Change-Id: Id952c7928c301fcc35d226e117dc19010b42776a
Reviewed-on: https://gerrit.openafs.org/14185
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-09-14 12:37:15 -04:00
Michael Meffie
a3aac5106b pts: Fix stringop-overflow warnings
The ptutil functions are defined to accept bounded character arrays for
user and group names. As of GCC 11, callers which provide the names as
string literals now trigger the stringop-overflow warning, since the
regions provided by the string literals are smaller than the bounded
areas.

    error: ‘pr_ChangeEntry’ accessing 64 bytes in a region of size 1
           [-Werror=stringop-overflow=]
    note: referencing argument 4 of type ‘char *’

    error: ‘pr_IsAMemberOf’ accessing 64 bytes in a region of size 22
           [-Werror=stringop-overflow=]
    note: referencing argument 2 of type ‘char *’

    error: ‘pr_CreateUser’ accessing 64 bytes in a region of size 16
           [-Werror=stringop-overflow=]
    note: referencing argument 1 of type ‘char *’

    error: ‘pr_Delete’ accessing 64 bytes in a region of size 16
           [-Werror=stringop-overflow=]
    note: referencing argument 1 of type ‘char *’

Update the callers in pts and testpt which pass literal strings. Instead
of passing char pointers to literal strings, assign the strings to
prname buffers and pass the prname buffers to the pr utility functions.

Change-Id: I7d8c67aa28d21bb6889ef92a2193a77b54c83cb1
Reviewed-on: https://gerrit.openafs.org/14769
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-09-06 21:50:26 -04:00
Michael Meffie
7924aecf95 ptserver: Fix CreateEntry() stringop-overflow warnings
The CreateEntry() prototype has been fixed to match the function
definition, so callers are expected to provide bounded arrays for the
user or group name. Fix the InitialGroup() macro which is used to set
the built-in names using string literal to avoid stringop-overflow
warnings.

    error: ‘CreateEntry’ accessing 64 bytes in a region of size 22 [-Werror=stringop-overflow=]
            code = CreateEntry(tt, (name), &temp, /*idflag*/1, flag, SYSADMINID, SYSADMINID); \

    note: in expansion of macro ‘InitialGroup’
           InitialGroup(SYSADMINID, "system:administrators");
    note: referencing argument 2 of type ‘char *’
    note: in a call to function ‘CreateEntry’
            CreateEntry(struct ubik_trans *at, char aname[PR_MAXNAMELEN], ...

    (Repeated for "system:backup", "system:anyuser", "system:authuser",
    "system:ptsviewers", and "anonymous".)

Change-Id: I7a37d4c8e191ffff52c2fdc1ed3783f4c3592b11
Reviewed-on: https://gerrit.openafs.org/14789
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>
2021-09-06 19:22:52 -04:00
Andrew Deason
02c3d56956 afs: Avoid touching CBRs after free
Currently, we free our CBR structures in shutdown_vcache, but later on
in shutdown_server, we call afs_FreeCBR on each one that's attached to
a struct server. afs_FreeCBR doesn't actually free the memory; it just
modifies some pointers to put the CBR on the free list. Since we do
this after the underlying memory has been freed, it can cause a panic
during shutdown since the structures are no longer valid.

To avoid this, make the afs_FreeCBR calls inside shutdown_vcache,
right before the memory is freed.

Change-Id: I142126d6aa811762b6c234d05abdac3764dad887
Reviewed-on: https://gerrit.openafs.org/14165
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
2021-09-05 12:15:43 -04:00