Lines Matching +full:global +full:- +full:halt
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
81 #include <crypto/rijndael/rijndael-api-fst.h>
244 /* Context information for dump-debuggers, saved by the dump_savectx() macro. */
305 error = mac_system_check_reboot(td->td_ucred, uap->opt);
310 if (uap->opt & RB_REROOT)
313 kern_reboot(uap->opt);
426 dumping--;
454 * kern_reboot(9): Shut down the system cleanly to prepare for reboot, halt, or
526 /* Now that we're going to really halt the system... */
558 * Mark the filesystem containing currently-running executable
561 vp = curproc->p_textvp;
565 mp = vp->v_mount;
586 * Remove the filesystem containing currently-running executable
590 * Also preserve /dev - forcibly unmounting it could cause driver
641 * If the shutdown was a clean halt, behave accordingly.
655 case -1: /* No console, just die */
675 if (panic_reboot_wait_time != -1) {
676 printf("Automatic reboot in %d seconds - "
680 loop > 0; --loop) {
683 if (cncheckc() != -1)
689 } else { /* zero time specified - reboot NOW */
692 printf("--> Press a key on the console to reboot,\n");
693 printf("--> or switch off the system now.\n");
710 * - it disables interrupts avoiding CPU0 preemption
712 * - it avoids deadlocks against smp_rendezvous() or, more
713 * generally, threads busy-waiting, with this spinlock held,
806 if (error != 0 || req->newptr == NULL)
829 * re-enter panic/kdb.
968 kdb_enter(KDB_WHY_PANIC, "re-panic");
971 td->td_flags |= TDF_INPANIC;
987 * soft-updates inconsistencies.
1028 kproc_shutdown_wait, p->p_comm);
1048 kproc_shutdown_wait, td->td_name);
1075 sbuf_cat(&sb, di->di_devname);
1102 arc4rand(kdc->kdc_iv, sizeof(kdc->kdc_iv), 0);
1104 kdc->kdc_encryption = encryption;
1105 switch (kdc->kdc_encryption) {
1107 if (rijndael_makeKey(&kdc->kdc_ki, DIR_ENCRYPT, 256, key) <= 0)
1111 chacha_keysetup(&kdc->kdc_chacha, key, 256);
1117 kdc->kdc_dumpkeysize = dumpkeysize;
1118 kdk = kdc->kdc_dumpkey;
1119 kdk->kdk_encryption = kdc->kdc_encryption;
1120 memcpy(kdk->kdk_iv, kdc->kdc_iv, sizeof(kdk->kdk_iv));
1121 kdk->kdk_encryptedkeysize = htod32(encryptedkeysize);
1122 memcpy(kdk->kdk_encryptedkey, encryptedkey, encryptedkeysize);
1148 SHA256_Update(&ctx, kdc->kdc_iv, sizeof(kdc->kdc_iv));
1150 bcopy(hash, kdc->kdc_iv, sizeof(kdc->kdc_iv));
1152 switch (kdc->kdc_encryption) {
1154 if (rijndael_cipherInit(&kdc->kdc_ci, MODE_CBC,
1155 kdc->kdc_iv) <= 0) {
1161 chacha_ivsetup(&kdc->kdc_chacha, kdc->kdc_iv, NULL);
1168 kdk = kdc->kdc_dumpkey;
1169 memcpy(kdk->kdk_iv, kdc->kdc_iv, sizeof(kdk->kdk_iv));
1181 return (kdc->kdc_dumpkeysize);
1203 kdcomp->kdc_format = compression;
1204 kdcomp->kdc_stream = compressor_init(kerneldumpcomp_write_cb,
1205 format, di->maxiosize, kerneldump_gzlevel, di);
1206 if (kdcomp->kdc_stream == NULL) {
1210 kdcomp->kdc_buf = malloc(di->maxiosize, M_DUMPER, M_WAITOK | M_NODUMP);
1219 kdcomp = di->kdcomp;
1222 compressor_fini(kdcomp->kdc_stream);
1223 zfree(kdcomp->kdc_buf, M_DUMPER);
1228 * Free a dumper. Must not be present on global list.
1237 zfree(di->blockbuf, M_DUMPER);
1240 zfree(di->kdcrypto, M_EKCD);
1262 newdi->blockbuf = NULL;
1263 newdi->kdcrypto = NULL;
1264 newdi->kdcomp = NULL;
1265 strcpy(newdi->di_devname, devname);
1267 if (kda->kda_encryption != KERNELDUMP_ENC_NONE) {
1269 newdi->kdcrypto = kerneldumpcrypto_create(newdi->blocksize,
1270 kda->kda_encryption, kda->kda_key,
1271 kda->kda_encryptedkeysize, kda->kda_encryptedkey);
1272 if (newdi->kdcrypto == NULL) {
1281 if (kda->kda_compression != KERNELDUMP_COMP_NONE) {
1289 if (kda->kda_encryption == KERNELDUMP_ENC_AES_256_CBC) {
1294 newdi->kdcomp = kerneldumpcomp_create(newdi,
1295 kda->kda_compression);
1296 if (newdi->kdcomp == NULL) {
1301 newdi->blockbuf = malloc(newdi->blocksize, M_DUMPER, M_WAITOK | M_ZERO);
1311 * Create a new dumper and register it in the global list.
1322 index = kda->kda_index;
1343 index--;
1370 if (kda->kda_index == KDA_REMOVE_ALL)
1373 if (strcmp(di->di_devname, devname) != 0)
1379 if (kda->kda_index == KDA_REMOVE_DEV)
1382 if (di->kdcomp != NULL) {
1383 if (di->kdcomp->kdc_format != kda->kda_compression)
1385 } else if (kda->kda_compression != KERNELDUMP_COMP_NONE)
1388 if (di->kdcrypto != NULL) {
1389 if (di->kdcrypto->kdc_encryption != kda->kda_encryption)
1398 if (kda->kda_encryption != KERNELDUMP_ENC_NONE)
1405 * Remove and free the requested dumper(s) from the global list.
1436 if (!found && kda->kda_index == KDA_REMOVE)
1445 if (di->mediasize > 0 && length != 0 && (offset < di->mediaoffset ||
1446 offset - di->mediaoffset + length > di->mediasize)) {
1447 if (di->kdcomp != NULL && offset >= di->mediaoffset) {
1455 (intmax_t)offset, (intmax_t)di->mediaoffset,
1456 (uintmax_t)length, (intmax_t)di->mediasize);
1459 if (length % di->blocksize != 0) {
1464 if (offset % di->blocksize != 0) {
1478 switch (kdc->kdc_encryption) {
1480 if (rijndael_blockEncrypt(&kdc->kdc_ci, &kdc->kdc_ki, buf,
1484 if (rijndael_cipherInit(&kdc->kdc_ci, MODE_CBC,
1485 buf + size - 16 /* IV size for AES-256-CBC */) <= 0) {
1490 chacha_encrypt_bytes(&kdc->kdc_chacha, buf, buf, size);
1509 kdc = di->kdcrypto;
1524 length -= nbytes;
1540 if (length % di->blocksize != 0) {
1547 rlength = rounddown(length, di->blocksize);
1553 resid = length - rlength;
1554 memmove(di->blockbuf, (uint8_t *)base + rlength, resid);
1555 bzero((uint8_t *)di->blockbuf + resid, di->blocksize - resid);
1556 di->kdcomp->kdc_resid = resid;
1580 if (hdrsz > di->blocksize)
1584 kdc = di->kdcrypto;
1594 if (di->dumper_hdr != NULL)
1595 return (di->dumper_hdr(di, kdh));
1597 if (hdrsz == di->blocksize)
1600 buf = di->blockbuf;
1601 memset(buf, 0, di->blocksize);
1605 extent = dtoh64(kdh->dumpextent);
1608 error = dump_write(di, kdc->kdc_dumpkey,
1609 di->mediaoffset + di->mediasize - di->blocksize - extent -
1617 di->mediaoffset + di->mediasize - 2 * di->blocksize - extent -
1618 keysize, di->blocksize);
1620 error = dump_write(di, buf, di->mediaoffset + di->mediasize -
1621 di->blocksize, di->blocksize);
1638 * +-----------+------+-----+----------------------------+------+
1640 * +-----------+------+-----+----------------------------+------+
1641 * 1 blk opt <------- dump extent --------> 1 blk
1664 kdc = di->kdcrypto;
1669 key = keysize > 0 ? kdc->kdc_dumpkey : NULL;
1676 if (di->dumper_start != NULL) {
1677 error = di->dumper_start(di, key, keysize);
1679 dumpextent = dtoh64(kdh->dumpextent);
1680 span = SIZEOF_METADATA + dumpextent + 2 * di->blocksize +
1682 if (di->mediasize < span) {
1683 if (di->kdcomp == NULL)
1694 dumpextent = di->mediasize - span + dumpextent;
1695 kdh->dumpextent = htod64(dumpextent);
1701 di->dumpoff = di->mediaoffset + di->mediasize - di->blocksize -
1704 di->origdumpoff = di->dumpoff;
1714 if (di->kdcrypto != NULL)
1715 error = dump_encrypted_write(di, virtual, di->dumpoff, length);
1718 error = dump_write(di, virtual, di->dumpoff, length);
1720 di->dumpoff += length;
1734 if (di->kdcomp != NULL) {
1736 if (length > di->maxiosize)
1738 buf = di->kdcomp->kdc_buf;
1740 return (compressor_write(di->kdcomp->kdc_stream, buf, length));
1756 return (di->dumper(di->priv, virtual, offset, length));
1770 if (di->kdcomp != NULL) {
1771 error = compressor_flush(di->kdcomp->kdc_stream);
1773 /* We have residual data in di->blockbuf. */
1774 error = _dump_append(di, di->blockbuf, di->blocksize);
1777 di->dumpoff -= di->blocksize - di->kdcomp->kdc_resid;
1778 di->kdcomp->kdc_resid = 0;
1787 kdh->dumplength = htod64(di->dumpoff - di->origdumpoff);
1788 kdh->parity = 0;
1789 kdh->parity = kerneldump_parity(kdh);
1791 compressor_reset(di->kdcomp->kdc_stream);
1809 strlcpy(kdh->magic, magic, sizeof(kdh->magic));
1810 strlcpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture));
1811 kdh->version = htod32(KERNELDUMPVERSION);
1812 kdh->architectureversion = htod32(archver);
1813 kdh->dumplength = htod64(dumplen);
1814 kdh->dumpextent = kdh->dumplength;
1815 kdh->dumptime = htod64(time_second);
1817 kdh->dumpkeysize = htod32(kerneldumpcrypto_dumpkeysize(di->kdcrypto));
1819 kdh->dumpkeysize = 0;
1821 kdh->blocksize = htod32(di->blocksize);
1822 strlcpy(kdh->hostname, prison0.pr_hostname, sizeof(kdh->hostname));
1823 dstsize = sizeof(kdh->versionstring);
1824 if (strlcpy(kdh->versionstring, version, dstsize) >= dstsize)
1825 kdh->versionstring[dstsize - 2] = '\n';
1827 strlcpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring));
1828 if (di->kdcomp != NULL)
1829 kdh->compression = di->kdcomp->kdc_format;
1830 kdh->parity = kerneldump_parity(kdh);