Commit Graph

230 Commits

Author SHA1 Message Date
christos 73776b1cca From FreeBSD:
netsmb: Fix buggy/racy smb_strdupin()

smb_strdupin() tried to roll a copyin() based strlen to allocate a buffer
and then blindly copyin that size.  Of course, a malicious user program
could simultaneously manipulate the buffer, resulting in a non-terminated
string being copied.

Later assumptions in the code rely upon the string being nul-terminated.

Just use copyinstr() and drop the racy sizing.

PR:		222687
Reported by:	Meng Xu <meng.xu AT gatech.edu>
Security:	possible local DoS
Sponsored by:	Dell EMC Isilon
2017-10-03 15:27:10 +00:00
riastradh 6b6142bc49 Reject negative offset/count for smb read/write.
Not clear that this is actually a problem for the kernel -- might
overwrite user's buffers or return garbage to user, but that's their
own damn fault.  But it's hard to imagine that negative offset/count
ever makes sense, and I haven't ruled out a problem for the kernel.
2017-07-28 14:45:59 +00:00
riastradh 7856833155 Reject negative ioc_setupcnt. 2017-07-28 14:40:42 +00:00
riastradh cf6e54504a Plug another overflow: refuse bogus sa_len from user. 2017-07-28 14:37:27 +00:00
riastradh 8fe0fa733b Reject allocations for too-small buffers from userland.
From Ilja Van Sprundel.
2017-07-28 14:20:46 +00:00
maxv 79a9312842 Uninitialized vars, found by brainy 2016-08-15 08:17:35 +00:00
pgoyette e615742559 Rearrange so that error check is only done after error has been set.
CID 1364141
2016-07-18 21:03:01 +00:00
pgoyette b380080ebc Now that we're only calling devsw_attach() in the modular driver, it
is not ok for the driver/module to already exist.  So don't ignore
EEXIST.
2016-07-17 02:48:07 +00:00
pgoyette d8be519d13 Ooops - previous change was over-zealous. We still need the cdevsw for
the built-in case.  Restore it.
2016-07-17 00:33:28 +00:00
pgoyette c5aa6dee64 Finish previous - now that we're not calling devsw_attach unnecessarily,
we can enclose some additional variables in #ifdef _MODULE / #endif
2016-07-17 00:27:03 +00:00
pgoyette 6eb90f9524 Rather than calling devsw_attach() and ignoring the EEXIST error when
the driver is already built-in to the kernel, don't bother calling.
2016-07-17 00:17:14 +00:00
christos e7ae23fd9e include "ioconf.h" to get the 'void <driver>attach(int count);' prototype. 2015-08-20 14:40:16 +00:00
ozaki-r b71bd7bda7 Remove leftover IPX-related stuffs
No objection on tech-kern and tech-net.
2015-05-25 08:29:01 +00:00
rtr 7d22c643f0 pass connect address directly to soconnect()
instead of allocating an mbuf, copying the address into it and then
mtod()'ing it back to a sockaddr * for soconnect.
2015-05-22 22:05:32 +00:00
rtr fd12cf39ee make connect syscall use sockaddr_big and modify pr_{send,connect}
nam parameter type from buf * to sockaddr *.

final commit for parameter type changes to protocol user requests

* bump kernel version to 7.99.15 for parameter type changes to pr_{send,connect}
2015-05-02 17:18:03 +00:00
nakayama 8c1c14022f Adjust smbfs/netsmb for filenames byte length changes that come as
a result of iconv conversion.  Most codes are taken from FreeBSD.
2014-11-15 18:52:44 +00:00
nakayama fb45a1eb84 Make rump_smbfs(8) uses host iconv(3) to convert filenames
character set.
2014-11-15 18:49:04 +00:00
matt 82ef6ef7b8 Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.
2014-09-05 09:26:16 +00:00
dholland f9228f4225 Add d_discard to all struct cdevsw instances I could find.
All have been set to "nodiscard"; some should get a real implementation.
2014-07-25 08:10:31 +00:00
rmind 4ae03c1815 - Split off PRU_ATTACH and PRU_DETACH logic into separate functions.
- Replace malloc with kmem and eliminate M_PCB while here.
- Sprinkle more asserts.
2014-05-19 02:51:24 +00:00
pooka 545c78295e whoops, remove testing printf 2014-04-25 15:54:12 +00:00
pooka 2324105436 Remove pollsock(). Since it took only a single socket, it was essentially
a complicated way to call soreceive() with a sb_timeo.  The only user
(netsmb) already did that anyway, so just had to delete the call to
pollsock().
2014-04-25 15:52:45 +00:00
dholland a68f9396b6 Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
2014-03-16 05:20:22 +00:00
joerg 5698ed750d Don't dereference NULL pointers. 2014-02-20 11:08:57 +00:00
nakayama fb4e31b6db Improve smbfs timestamp handling.
Don't round timestamp to 2 seconds resolution if the server
supports the CAP_INFOLEVEL_PASSTHRU capability.
2012-11-30 23:24:21 +00:00
nakayama 5f60ff96cb - fix endian cofusion around FID, which is used as is, so no need
to do byte swapping.
- put right value to ByteCount of SMB_COM_NT_CREATE_ANDX request.

The fix makes smbfs actually works on big-endian port.
2012-11-24 19:48:24 +00:00
nakayama 361b8e4249 Tabify. 2012-05-12 01:40:37 +00:00
nakayama 0c073a1ca9 Since "len" has changed to (unsinged) size_t, the while loop
condition (len > 0) became less able to detect its underflow.
So check the subtrahend to avoid the underflow.

Should fix PR kern/44092.
2012-05-11 14:51:39 +00:00
dsl e05eb71de5 Remove everything to do with 'struct malloc_type' and the malloc link_set.
To make code in 'external' (etc) still compile, MALLOC_DECLARE() still
  has to generate something of type 'struct malloc_type *', with
  normal optimisation gcc generates a compile-time 0.
MALLOC_DEFINE() and friends have no effect.
Fix one or two places where the code would no longer compile.
2012-04-29 20:27:31 +00:00
elad 0c9d8d15c9 Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

    http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
    http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
    http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.
2012-03-13 18:40:26 +00:00
christos 8b0d7f915b rename SMBFS_MAXFNAMELEN to SMBFS_MAXNAMLEN for consistency 2011-09-27 02:05:10 +00:00
christos 9d292e0f12 remove unused constant 2011-09-27 01:16:35 +00:00
chs 4364c9c0d3 don't mix static and non-static MALLOC_DEFINE()s in the same file,
it fails to compile with gcc 4.5 on alpha.
2011-09-25 13:42:30 +00:00
plunky 7f3d4048d7 NULL does not need a cast 2011-08-31 18:31:02 +00:00
pooka f4f60017b9 * remove #ifdef nonsense (which caused the lossage in the first place)
* make it a DRIVER so that it autoloads when /dev/nsmb is opened
2010-12-17 14:27:34 +00:00
pooka 3a3ba15647 Try to unbreak module a little. It would be really nice to not
utterly break things in the name of modularization, especially if
avoiding breakage takes 2min.
2010-12-17 13:24:45 +00:00
pooka 8fb9443f66 unifdef -D__NetBSD__ 2010-12-17 13:05:29 +00:00
ahoka 3531a9ba6c take two on module support
XXX this wont work as a builtin module
2010-12-15 12:58:13 +00:00
christos a39b3d540d Back this out. Fails lockdebug with duplicate lock initialization.
Please test with LOCKDEBUG!
2010-12-11 04:21:17 +00:00
ahoka 6110939092 Module support for NetBSD 2010-12-10 19:44:18 +00:00
christos 94320bc4fd Convert sizes/lengths to unsigned (size_t) or uint32_t
(for binary compatibility).
2010-07-12 02:58:01 +00:00
hannken 245651a23d Remove vlockmgr(). Generic vnode lock operations now use a rwlock located
in the vnode.  All LK_* flags move from sys/lock.h to sys/vnode.h.  Calls
to vlockmgr() in file systems get replaced with VOP_LOCK() or VOP_UNLOCK().

Welcome to 5.99.34.

Discussed on tech-kern.
2010-07-01 13:00:54 +00:00
tron f996d27b06 Fix cut & paste error spotted by Nicolas Joly. 2009-10-18 23:20:31 +00:00
tron 9c260cf349 Fix detection of SMB capabilities according to the CIFS spec:
1.) SMB_CAP_LARGE_FILES advertises support for 64-bit file offsets.
2.) SMB_CAP_LARGE_READX and SMB_CAP_LARGE_WRITEX advertise support for
    large reads and writes (larger than 64KB).
The code previously only used SMB_CAP_LARGE_READX and SMB_CAP_LARGE_WRITEX
which is not correct and doesn't work for the Apple Time Capsule which
only supports SMB_CAP_LARGE_FILES. With these changes SMBFS can copy a
5GB to a Time Capsule and read it back without problems.

Thanks a lot to Allen Briggs for pointing out the broke assumptions
and explaining the CIFS spec to me. This fixes PR kern/42175.
2009-10-18 22:53:36 +00:00
njoly 3ca0c64cb2 Do not call smb_rqpool_fini() on device close. Otherwise, we'll crash
trying to use destroyed pools for SMB request.
2009-09-21 14:13:35 +00:00
pooka df6e37fb47 Convert POOL_INITs to proper cons/destructors. 2009-09-12 12:52:21 +00:00
pooka d42676af17 add comment to previous stating periodic wakeups can be nuked
once smb is mpsafe.
2009-09-04 16:18:34 +00:00
pooka d25f4faa30 defensive programming: wake up iod thread once a second "just in case" 2009-09-04 16:16:52 +00:00
pooka 56df608091 Send data for as long as there is new data available. Otherwise
there was a danger of smb_iod_recvall() blocking, hence releasing
the kernel lock, new data creeping into the queue, and a wakeup
being missed (well, there's still a race, but since it's theoretical
enough for me to never have encountered it, I'll rather solve it
by periodic wakeups).
2009-09-04 16:12:45 +00:00
tls 8c208552ae Grr. One last thing from the upcall-direction patch which I failed to
check in correctly.
2009-09-04 01:41:06 +00:00