Commit graph

2684 commits

Author SHA1 Message Date
Warner Losh
18e42bdf1a da: Add quirk for ADATA USB Drive
ADATA USB Drive lies about the RC16, so add a quirk to ignore it.

MFC After: 3 days
PR: 188999
Sponsored by:		Netflix

(cherry picked from commit f11b6ce4a3bc6d455dbec375218c01ce9b6b5dc2)
2024-11-12 21:55:04 -07:00
Pierre Pronchery
2e7f4728fa ctl: limit memory allocation in pci_virtio_scsi
The virtio_scsi device allows a VM guest to directly send SCSI commands
(ctsio->cdb array) to the kernel driver exposed on /dev/cam/ctl
(ctl.ko).

All kernel commands accessible from the guest are defined by
ctl_cmd_table.

The command ctl_persistent_reserve_out (cdb[0]=0x5F and cbd[1]=0) allows
the caller to call malloc() with an arbitrary size (uint32_t). This can
be used by the guest to overload the kernel memory (DOS attack).

Reported by:    Synacktiv
Reviewed by:	asomers
Security:       HYP-08
Sponsored by:   The Alpha-Omega Project
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D46044

(cherry picked from commit 64b0f52be2c9d7bcecebfeef393f8ec56cb85f47)
2024-10-11 11:53:17 -04:00
Zhenlei Huang
d2d4758456 ctl: Stop checking for failures from malloc(M_WAITOK)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D45852

(cherry picked from commit 8e6dd4185871cd9b785869178ab2191a0d6c0b53)
2024-09-30 12:44:14 +08:00
Bjoern A. Zeeb
6f58191b30 mmccam: fix mmcsd disk aliases
For EXT_CSD_PART_CONFIG_ACC_BOOT<n> and possibly others with suffixes
we fail to create proper disk aliases (symlinks), which shows up as
g_dev_taste: make_dev_alias_p() failed (name=mmcsd0, error=17)

In this case we ended up with the followng two:
  /dev/mmcsd0 -> sdda0
  /dev/mmcsd1 -> sdda0boot1
Note that (i) it should be mmcsd0boot1 and not mmcsd1 and that
(ii) there is no mmcsd0boot0 (failed above as it tried to create a
second mmcsd0).

Adjust the code (using a highly simplified version--compared to my
original approach--suggested by imp) using an extended format string
with (sdda/mmcsd) prefix as first argument to create proper names.

Reviewed by:	imp
Differential Revision: https://reviews.freebsd.org/D43538

(cherry picked from commit a84d91d81a6f3eeb4949c4fb3440e0634f2b953a)
2024-09-28 10:35:11 +00:00
Alan Somers
c6d11ae455 ctl: fix uninitialized data used by PREVENT ALLOW MEDIUM REMOVAL
Zero-initialize the bitmap of preventers.  Otherwise, the START STOP
UNIT command may not have the intended effect.

Sponsored by:	Axcient
Reviewed by:    emaste, markj
Pull Request:   https://github.com/freebsd/freebsd-src/pull/1409

(cherry picked from commit 0f2b2276abc305905e7d88619a7abca26b0dd7eb)
2024-09-19 14:24:04 -06:00
Alan Somers
f07fc92df0 ctladm: don't require the use of "-p" with "port -r"
When removing a port, the ioctl frontend requires the "-p" argument.
But other frontends, like cfiscsi, do not.  So don't require that
argument in the ctladm command.  The frontend driver will report an
error if any required argument is missing.

Sponsored by:	Axcient
Reviewed by:    mav
Pull Request:   https://github.com/freebsd/freebsd-src/pull/1279

(cherry picked from commit edbd489d09babebdc6c03924a912013be584c409)

ctladm: don't require the use of "-p" with "port -r", part 2

* Remove a now superfluous FALLTHROUGH hint
* Don't specify "-p" with an empty argument in the tests

Reported by:	jhb

(cherry picked from commit 7f50027321db3b08477f6236abded0297e9e5ed8)
2024-09-19 14:03:30 -06:00
Alan Somers
e48e80fcb7 ctladm: better documentation for adding and removing cfiscsi ports
MFC after:	2 weeks
Sponsored by:	Axcient
Reviewed by:    mav
Pull Request:   https://github.com/freebsd/freebsd-src/pull/1279

(cherry picked from commit afecc74cd7158da8e89c26c5267bc715c2417fe7)
2024-09-19 14:03:29 -06:00
Pierre Pronchery
803e0c2ab2 ctl: fix Out-Of-Bounds access in ctl_report_supported_opcodes
This vulnerability is directly accessible to a guest VM through the
pci_virtio_scsi bhyve device.

In the function ctl_report_supported_opcodes() accessible from the VM,
the option RSO_OPTIONS_OC_ASA does not check the requested
service_action value before accessing &ctl_cmd_table[].

Reported by:	Synacktiv
Reviewed by:	asomers
Security:	FreeBSD-SA-24:11.ctl
Security:	CVE-2024-42416
Security:	HYP-06
Sponsored by:	The Alpha-Omega Project
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D46027

(cherry picked from commit af438acbfde3d25dbdc82b2b3d72380f0191e9d9)
2024-09-04 14:59:53 +00:00
Pierre Pronchery
cdfdb3b008 ctl: fix memory disclosure in read/write buffer commands
The functions ctl_write_buffer() and ctl_read_buffer() are vulnerable to
a kernel memory disclosure caused by an uninitialized kernel allocation.
If one of these functions is called for the first time for a given LUN, a
kernel allocation is performed without the M_ZERO flag. Then a call to
ctl_read_buffer() returns the content of this allocation, which may
contain kernel data.

Reported by:	Synacktiv
Reviewed by:	asomers
Reviewed by:	jhb
Security:	FreeBSD-SA-24:11.ctl
Security:	CVE-2024-8178
Security:	HYP-05
Sponsored by:	The Alpha-Omega Project
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D45952

(cherry picked from commit ea44766b78d639d3a89afd5302ec6feffaade813)
2024-09-04 14:59:52 +00:00
Alan Somers
29937d7a1a ctl: fix Use-After-Free in ctl_write_buffer
The virtio_scsi device allows a guest VM to directly send SCSI commands
to the kernel driver exposed on /dev/cam/ctl. This setup makes the
vulnerability directly accessible from VMs through the pci_virtio_scsi
bhyve device.

The function ctl_write_buffer sets the CTL_FLAG_ALLOCATED flag, causing
the kern_data_ptr to be freed when the command finishes processing.
However, the buffer is still stored in lun->write_buffer, leading to a
Use-After-Free vulnerability.

Since the buffer needs to persist indefinitely, so it can be accessed by
READ BUFFER, do not set CTL_FLAG_ALLOCATED.

Reported by:	Synacktiv
Reviewed by:	Pierre Pronchery <pierre@freebsdfoundation.org>
Reviewed by:	jhb
Security:	FreeBSD-SA-24:11.ctl
Security:	CVE-2024-45063
Security:	HYP-03
Sponsored by:	Axcient
Sponsored by:	The Alpha-Omega Project
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D46424

(cherry picked from commit 670b582db6cb827a8760df942ed8af0020a0b4d0)
2024-09-04 14:59:52 +00:00
John Baldwin
e8edea1b4c nda: Use the NVMEV macro instead of expanded versions
Reviewed by:	chuck
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D43596

(cherry picked from commit 2cb78e71503ec9a73054a6f70908c5f20c2ceb73)
2024-08-26 13:26:00 -04:00
Ed Maste
131b7dcb2f ctl: avoid heap info leak in ctl_request_sense
Previously 3 bytes of data from the heap could be leaked to ctl
consumers.

Reported by:	Synacktiv
Reviewed by:	asomers, mav
Sponsored by:	The Alpha-Omega Project
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D46091

(cherry picked from commit db87c98168b1605f067d283fa36a710369c3849d)
2024-08-26 09:23:37 -04:00
Matthew Grooms
4c2ea6e26d da: Update trim stats for WRITE SAME and ATA TRIM
The scsi UNMAP path updated trim stats in the da sysctl, but the ATA
TRIM passthru and WRITE SAME paths did not. Add code so they do.

PR: 277637
Reviewed by: imp (tweaked WS path to update ranges)

(cherry picked from commit 12117d0e9314d1706508386c1c49ace2de578b31)
2024-05-20 13:23:40 -06:00
John Baldwin
7d763eadd3 cam: Check if cam_simq_alloc fails for the xpt bus during module init
This is very unlikely to fail (and if it does, CAM isn't going to work
regardless), but fail with an error rather than a gauranteed panic via
NULL pointer dereference.

PR:		276770
Reported by:	Qiushi <w290680224@gmail.com>

(cherry picked from commit eb86c6c5b462c996e44c45ba496937b75ef22da3)
2024-04-08 10:53:43 -07:00
Andriy Gapon
bf11fee6a5 ata_da: add quirk to disable NCQ TRIM for Samsung 860/870 SSDs
NCQ TRIM for Samsung 860/870 SSDs results in data corruption on systems
with some SATA controllers.

This can be easily reproduced using ZFS which uses TRIM and is able to
detect block content changes.

Linux bug report for this issue:
 https://bugzilla.kernel.org/show_bug.cgi?id=201693

Since at present we can not limit a quirk based on the contorller / SIM,
apply the quirk in all cases.

Reviewed by:	imp

(cherry picked from commit c01af41c3c8fdd570764ff9b6bfbad6ac9ca1664)
2024-03-16 17:13:27 +02:00
Andriy Gapon
50aa223234 scsi_da: add 4K quirks for Samsung SSD 860 and 870
Although the actual flash page size is either 8K or 16K for those
devices (according to different sources of various reliability), they
seem to be optimized for the "industry-standard" emulated 4K block size.

To do: consolidate very similar Samsung SSD entries for 830 - 870
models.

(cherry picked from commit b7dce5b8e988f47784c55aa096541deda7b1aaeb)
2024-03-16 17:12:53 +02:00
Warner Losh
47fff7407c ada: Another NCQ Trim instability drive
The Seagate IronWolf 110 SATA SSD drive has been reported to be unstable
with NCQ trim enabled.

PR: 264139
Sponsored by:		Netflix

(cherry picked from commit a6cef617660a424fcaa8343787f96d0ae720a284)
2024-03-11 22:46:28 -06:00
Mark Johnston
c50eeb321b scsi_cd: Remove commented-out code
This is left over from before the implementation of asynchronous media
probing, which was committed in dd78f43259
("scsi_cd: make the media check asynchronous") quite a while ago now.

No functional change intended.

MFC after:	1 week
Reviewed by:	imp, avg
Differential Revision:	https://reviews.freebsd.org/D43650

(cherry picked from commit 0c0ec5c8cc482e68e17e2389df4e550f65242985)
2024-02-09 09:55:45 -05:00
Mark Johnston
212af7b613 scsi_cd: Maintain a periph reference during media checks
Otherwise nothing prevents the asynchronous media check state machine
from running after the periph has been destroyed, which can result in a
double free.  Acquire the reference even when performing a synchronous
check, since that doesn't hurt and keeps things simpler.

PR:		276251
Reviewed by:	imp
Fixes:		dd78f43259 ("scsi_cd: make the media check asynchronous")
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43525

(cherry picked from commit c961afe82596bdeb7e6a8626f02ddb181c8a24b6)
2024-02-09 09:55:45 -05:00
Mark Johnston
fe44b0cae6 scsi_cd: Use a bool for the second parameter of cdcheckmedia()
No functional change intended.

Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43525

(cherry picked from commit b1710124ff14f96db4c2a8fa37fc7c7b433fb176)
2024-02-09 09:55:45 -05:00
John Baldwin
873bef94a2 ctl: Add missing comma after CTL_FLAG_ALREADY_DONE
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42930

(cherry picked from commit 105eee97b0253fe6b66bf4c33fe3c4e17f30f05f)
2024-01-18 14:40:45 -08:00
John Baldwin
99f93a33ae ctl_frontend.h: Note that ctl_port.frontend is set by the FETD
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42931

(cherry picked from commit dfbb6f2e5991ecc3143d75f2358ec7f12f0656b1)
2024-01-18 14:40:39 -08:00
John Baldwin
0469f7ab3c ctl: Always return errno values from ctl_port_register
Return EBUSY instead of a bare 1 if a port number is already active.

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42929

(cherry picked from commit e03e77ba4d0570511fdc1be192459e1160c650a6)
2024-01-18 14:40:31 -08:00
Mark Johnston
185634d86d targ: Handle errors from suword()
In targstart() we are already handling an error and have no go way to
signal the failure to upper layers, so ignore the return value of
suword() there.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43202

(cherry picked from commit 904cd456f0f95c10fdb4c99a0118f30d23242dec)
2024-01-11 09:26:53 -05:00
Mark Johnston
758c5b5c02 cam: Let cam_periph_unmapmem() return an error
As of commit b059686a71, cam_periph_unmapmem() can legitimately fail
if the copyout() operation fails.  However, this failure was never
signaled to upper layers.  In practice it is unlikely to occur
since cap_periph_mapmem() would most likely fail in such
circumstances anyway, but an error is nonetheless possible.

However, some code reading revealed a few paths where the return value
of cam_periph_mapmem() is not checked, and this is definitely a bug.
Add error checking there and let cam_periph_unmapmem() return errors
from copyout().

Reviewed by:	dab, mav
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D43201

(cherry picked from commit d068ea16e3264c2d62472a8acf794262cfe703dd)
2024-01-11 09:22:37 -05:00
Mark Johnston
55205beabb sa: Make sa_param_table[] const and static
No functional change intended.

Reviewed by:	ken, imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43204

(cherry picked from commit 46a6cfee1bb61145717166a3bbbd8dbad27fbf36)
2024-01-04 08:42:35 -05:00
Mark Johnston
9fcacefa38 sa: Check for errors from copyout()
This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by:	ken
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43203

(cherry picked from commit 4d3c234d8eb32f903d630b371208a0a931d3d5fe)
2024-01-04 08:42:26 -05:00
John Baldwin
950162c4d3 ctl: Use ctl_io_sbuf in ctl_process_done
This reduces a second copy of (mostly) the same code.

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42210

(cherry picked from commit e846a3e0168f9188a6eccedd52707c63fd83cba2)
2024-01-02 11:20:37 -08:00
John Baldwin
dba59c3567 ctl: Make ctl_private.h more self-contained
Include <sys/sysctl.h> for sysctl context types.

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42209

(cherry picked from commit fc8cf0a8deb8908fb17acc56e96f3f700c05136d)
2024-01-02 11:20:37 -08:00
John Baldwin
2996e219e4 ctl: Make ctl_ha.h more self-contained
Include <sys/queue.h> for queue macros

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42208

(cherry picked from commit 10b1a66934b0c1b252369c496952974f980441a4)
2024-01-02 11:20:37 -08:00
John Baldwin
15601268b9 ctl: Make ctl_io.h more self-contained
Include <cam/scsi/scsi_all.h> for struct scsi_sense_data.
Include <sys/queue.h> for queue macros.

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42207

(cherry picked from commit 4efebb3de39a2694169d3032fb6ca567409c2bcb)
2024-01-02 11:20:37 -08:00
John Baldwin
46b03fd898 ctl: Make ctl.h more self-contained
Make MALLOC_DECLARE conditional on <sys/malloc.h> and forward declare
several types.

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42206

(cherry picked from commit 55231cd180692c7299bff65e608dba20013ec0f7)
2024-01-02 11:20:37 -08:00
John Baldwin
2cad2d1a2a cam: Make <cam/scsi/scsi_all.h> more self-contained
Include <sys/malloc.h> in the kernel for struct malloc_type.

Reviewed by:	ken, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D42205

(cherry picked from commit 2e539c6f5aba657c69790d91130ceceeb0b8c38e)
2024-01-02 11:20:36 -08:00
Mark Johnston
cd4fa92589 ses: Add error checking for copyout() calls
This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by:	mav, imp, asomers
Tested by:	asomers
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43130

(cherry picked from commit 771501e96ffd7e314c338300a351ad76d28a2f69)
2024-01-01 19:29:50 -05:00
Mitchell Horne
9732eb8eae ctl_ha: don't shutdown threads if scheduler is stopped
In this case, just return.

Reviewed by:	markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D42341

(cherry picked from commit 9d61fd08499609a2c95d1c66f97587932b446f06)
2023-12-08 18:02:44 -04:00
Alexander Motin
f035d56e71 CAM: Use sbuf_new_for_sysctl() in more places
There is no need to allocate buffer, worry about overflows, etc.

MFC after:	2 weeks

(cherry picked from commit 1b44079584dc317230cf810c0fe0a8c401a5c791)
2023-12-06 10:35:02 -05:00
Alexander Motin
3a8271dc1d CAM: Remove return value from xpt_path_sbuf()
It is wrong to call sbuf_len() on third-party sbuf.  If that sbuf
has a drain function, it ends up in assertion.  But even would it
work, it would return not newly written length, but the full one.
Searching through the sources I don't see this value used.

(cherry picked from commit 6332e0f1a4b34707654d6ae2cd3c1e8799970d0b)
2023-12-06 10:34:38 -05:00
Zhenlei Huang
fb288d4939 cam/ata: Postpone removal of two compat sysctls until 15
Prefer UNMAPPEDIO and ROTATING from flags sysctl. See
 1. aeab0812e6 (Add flags sysctl to ada)
 2. cf3ff63e55 (Convert unmappedio over to a flag)
 3. 96eb32bf0f (Convert rotating to a flag bit)

Reviewed by:	imp, ken, #cam
MFC after:	immediately (we want this in 14.0)
Differential Revision:	https://reviews.freebsd.org/D42402

(cherry picked from commit d24729b2fd66a87c2b925b0c30e46bb0a9d6446a)
2023-11-02 13:20:39 +08:00
Zhenlei Huang
4bf3810546 cam/scsi: Add sysctl flag CTLFLAG_TUN to loader tunable
The sysctl variable 'kern.cam.scsi_delay' is actually a loader tunable.
Add sysctl flag CTLFLAG_TUN to it so that `sysctl -T` will report it
correctly.

No functional change intended.

Reviewed by:	kib, imp (for #cam)
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D42113

(cherry picked from commit e2ad7ce37b1a354750d2dd3567e77f72edeb7e1d)
2023-10-12 12:08:11 +08:00
Warner Losh
d9fee1d021 cam/scsi_da: Bump deprecation one release.
These are still used in a quick poll that I've done, so we can't remove
them in 14. Reset the removal to FreeBSD 15.

Sponsored by:		Netflix
2023-08-23 22:34:41 -06:00
Warner Losh
031beb4e23 sys: Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:58 -06:00
Warner Losh
685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh
71625ec9ad sys: Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:24 -06:00
Warner Losh
2ff63af9b8 sys: Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:18 -06:00
Warner Losh
95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Gordon Bergling
586eda6b24 cam(4): Fix a typo in a source code comment
- s/uppper/upper/

MFC after:	3 days
2023-08-02 11:14:53 +02:00
John Baldwin
83453b46e8 mmc_xpt: Update function name in debug trace
Reported by:	mav
Fixes:		7eb538974c cam mmc_xpt/nvme_xpt: Add _sbuf variants of {an,de}nounce xport and proto ops
2023-08-01 16:14:58 -07:00
John Baldwin
b2c44f1fc1 cam: Remove non-sbuf announce/denounce proto and xport ops
Reviewed by:	mav, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D41264
2023-08-01 15:25:38 -07:00
John Baldwin
0a57cdd971 cam_xpt: Reimplement xpt_*nounce_periph in terms of the _sbuf versions
Use an sbuf that drains to printf to avoid duplicating code in the two
versions of each function.

Reviewed by:	mav
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D41263
2023-08-01 15:24:36 -07:00
John Baldwin
b82711764c cam_xpt: Remove fallbacks for non-sbuf protocol methods
This includes removing the kern.cam.announce_nosbuf sysctl.

Reviewed by:	mav, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D41262
2023-08-01 15:24:10 -07:00