Commit Graph

8135 Commits

Author SHA1 Message Date
Conrad Meyer
fb0eab090e dhclient: Fix the trivial buffer overruns correctly
A DHCP client identifier is simply the hardware type (one byte) concatenated
with the hardware address (some variable number of bytes, but at most 16).
Limit the size of the temporary buffer to match and the rest of the
calculations shake out correctly.

This is a follow-up to the incorrect r299512, reverted in r300172.

CIDs:		1008682, 1305550
Sponsored by:	EMC / Isilon Storage Division
2016-05-18 23:41:55 +00:00
Conrad Meyer
4441bd735f Revert r299512
It broke client identifiers because I misunderstood the intent of the code.
There is still a minor issue detected by Coverity (at least, I can't find where
the code proves it isn't an issue).  I'll follow up with a better fix for the
CIDs.

Reported by:	Ian FREISLICH
Sponsored by:	EMC / Isilon Storage Division
2016-05-18 23:35:37 +00:00
Andrey V. Elsukov
825f02a9ed Make ipfw internal olist output more user friendly.
Print object type as string for known types.

Obtained from:	Yandex LLC
Sponsored by:	Yandex LLC
2016-05-17 11:22:08 +00:00
Andrey V. Elsukov
2685841b38 Make named objects set-aware. Now it is possible to create named
objects with the same name in different sets.

Add optional manage_sets() callback to objects rewriting framework.
It is intended to implement handler for moving and swapping named
object's sets. Add ipfw_obj_manage_sets() function that implements
generic sets handler. Use new callback to implement sets support for
lookup tables.
External actions objects are global and they don't support sets.
Modify eaction_findbyname() to reflect this.
ipfw(8) now may fail to move rules or sets, because some named objects
in target set may have conflicting names.
Note that ipfw_obj_ntlv type was changed, but since lookup tables
actually didn't support sets, this change is harmless.

Obtained from:	Yandex LLC
Sponsored by:	Yandex LLC
2016-05-17 07:47:23 +00:00
Don Lewis
c98907a4f4 Add an assertion to catch a potential underflow in an array index
calculation, though this should not happen in the current code.

Reported by:	Coverity
CID:		1008486
MFC after:	3 weeks
2016-05-16 08:07:32 +00:00
Marcelo Araujo
f8358c11a5 For pointers use NULL instead of 0.
MFC after:	2 weeks.
2016-05-16 00:36:12 +00:00
Marcelo Araujo
798a749aae For pointers use NULL instead of 0.
MFC after:	2 weeks.
2016-05-16 00:35:39 +00:00
Marcelo Araujo
2ef6931a15 For pointers use NULL instead of 0.
MFC after:	2 weeks.
2016-05-16 00:34:48 +00:00
Don Lewis
c871174916 Use strlcpy() instead of strncpy() when copying ifname to ensure
that it is NUL terminated.  Additional NUL padding is not required
for short names.

Use sizeof(destination) in a few places instead of IFNAMSIZ.

Cast afp->af_ridreq and afp->af_addreq  to make the intent of
the code more obvious.

Reported by:	Coverity
CID:		1009628, 1009630, 1009631, 1009632, 1009633, 1009635, 1009638
CID:		1009639, 1009640, 1009641, 1009642, 1009643, 1009644, 1009645
CID:		1009646, 1009647, 1010049, 1010050, 1010051, 1010052, 1010053
CID:		1010054, 1011293, 1011294, 1011295, 1011296, 1011297, 1011298
CID:		1011299, 1305821, 1351720, 1351721
MFC after:	1 week
2016-05-16 00:25:24 +00:00
Pedro F. Giffuni
bdfd68dca7 routed(8): Use arc4random_uniform instead of arc4random.
Use arc4random_uniform() when the desired random number upper bound
is not a power of two.

While here, we don't need srandom() and friends anymore.

Obtained from:	OpenBSD (CVS rev. 1.20)
2016-05-15 06:06:22 +00:00
Pedro F. Giffuni
e09d48f656 routed(8): Misc. cleanups to squelch Coverity.
table.c:
Copy into fixed size buffer.

trace.c:
Argument got dup2() cannot be negative.
Copy into fixed size buffer.

CID:		1006785, 1006786, 271301
Obtained from:	NetBSD
MFC after:	2 weeks.
2016-05-15 03:04:21 +00:00
Pedro F. Giffuni
65e2bd0ab8 routed(8): Dereference before null check.
CID:		272432
Obtained from:	NetBSD (CVS ref. 1.16)
MFC after:	2 weeks.
2016-05-15 02:41:20 +00:00
Pedro F. Giffuni
7b011d21db routed(8): Avoid NULL de-reference and two possible memory leaks.
The reports and fixes are straightforward but it's nice to be able
to confirm against NetBSD.

CID:		271080, 272306, 272307
Obtained from:	NetBSD (CVS ref. 1.21 - 1.23)
MFC after:	2 weeks.
2016-05-15 02:30:34 +00:00
Pedro F. Giffuni
5728318b35 Avoid NULL de-references.
CID:		271079
Obtained from:	NetBSD
MFC after:	2 weeks.
2016-05-14 23:32:03 +00:00
Pedro F. Giffuni
365cb451d3 routed(8): Use arc4random.
CID:		1305962
Obtained from:	NetBSD (CVS Rev. 1.34, Itojun)
2016-05-14 23:22:19 +00:00
Pedro F. Giffuni
0b279f8c94 routed: Fix use after free.
For the multihomed case, ifp be used after being freed. NULL the value
after freeing it and avoid getting into the branch without reassigning
a new value.

CID:		272671
Obtained from:	NetBSD
MFC after:	2 weeks
2016-05-14 23:07:26 +00:00
Pedro F. Giffuni
562c5a82cb routed(8): use NULL instead of zero for pointers. 2016-05-14 22:40:08 +00:00
Don Lewis
eeb6394364 Check for socket creation success before calling bind().
Reported by:	Coverity
CID:		1194209
2016-05-12 05:43:54 +00:00
Conrad Meyer
021b92e5ba dhclient: Fix some trivial buffer overruns
There was some confusion about how to limit a hardware address to at most 16
bytes.  In some cases it would overrun a byte off the end of the array.
Correct the types and rectify the overrun.

Reported by:	Coverity
CIDs:		1008682, 1305550
Sponsored by:	EMC / Isilon Storage Division
2016-05-12 04:28:22 +00:00
Conrad Meyer
fdaa5d1c07 camcontrol(8): Fix another trivial double-free
Reported by:	Coverity
CID:		1331222
Sponsored by:	EMC / Isilon Storage Division
2016-05-11 22:25:14 +00:00
Conrad Meyer
3aeebae9ca camcontrol(8): Fix trival double-free
Reported by:	Coverity
CID:		1331223
Sponsored by:	EMC / Isilon Storage Division
2016-05-11 22:22:49 +00:00
Conrad Meyer
333d028407 fsck_ffs: Don't overrun mount device buffer
Maybe this case is impossible.  Either way, when attempting to "/dev/"-prefix a
non-global device name, check that we do not overrun the f_mntfromname buffer.

In this case, truncating (with strlcpy or similar) would not be useful, since
the f_mntfromname result of getmntpt() is passed directly to open(2) later.

Reported by:	Coverity
CID:		1006789
Sponsored by:	EMC / Isilon Storage Division
2016-05-11 16:20:23 +00:00
Edward Tomasz Napierala
377b6d1e7c When rerooting, take the init(8) path from argv[0] instead of fetching
it via kern.proc.pathname sysctl(2).  In some cases - booting from NFS
or rerooting after replacing the init binary with a new one - the sysctl
would fail.  In other cases - after upgrading, which moves the old init
to /sbin/init.bak - it would return /sbin/init.bak, which is the actual
path of the running init, instead of /sbin/init.

Reported by:	Melissa Jenkins <melissa-freebsd at littlebluecar.co.uk>, jilles@
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-11 10:03:13 +00:00
Edward Tomasz Napierala
126ba2193b When rerooting, ignore ESRCH returned from kill(2). I couldn't reproduce
this by myself, but apparently it sometimes happens when rerooting from
single user mode.

Reported by:	jilles@
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-11 09:30:18 +00:00
Edward Tomasz Napierala
b8a1930fcf Cosmetic fixes for growfs(8) - remove unneeded capitalization and a spurious
newline, clarify a message.

MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-05-11 09:26:23 +00:00
Edward Tomasz Napierala
e49345fa3d Update the example growfs(8) manual page to include information on how
to make the system "notice" the updated disk size.

(Relnotes, since I've forget to set it for "camcontrol reprobe", and
it's worth mentioning.)

MFC after:	1 month
Relnotes:	yes
Sponsored by:	The FreeBSD Foundation
2016-05-10 18:28:38 +00:00
Edward Tomasz Napierala
d68fae5849 Add "camcontrol reprobe" subcommand, and implement it for da(4).
This makes it possible to manually force updating capacity data
after the disk got resized. Without it it might be neccessary to
reboot before FreeBSD notices updated disk size under eg VMWare.

Discussed with:	imp@
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D6108
2016-05-10 15:46:33 +00:00
Baptiste Daroussin
997f8ff84f Rename getline with get_line to avoid collision with getline(3)
When getline(3) in 2009 was added a _WITH_GETLINE guard has also been added.
This rename is made in preparation for the removal of this guard
2016-05-10 11:35:03 +00:00
Andriy Voskoboinyk
db930544a3 ifconfig: fix check for 40 MHz channels while applying country/regdomain.
Do not use 20 MHz channel list while checking 40 MHz channels;
it may be different. Just use the corresponding list instead.

Tested by:	Masachika ISHIZUKA <ish@amail.plala.or.jp>

PR:		209328
2016-05-09 16:15:52 +00:00
Renato Botelho
89d18e14f1 Add missing parameters -N and -l to reroot and halt usage()
Approved by:	bapt
Sponsored by:	Rubicon Communications (Netgate)
Differential Revision:	https://reviews.freebsd.org/D6173
2016-05-06 20:49:14 +00:00
Pedro F. Giffuni
eabd8f1210 nvmecontrol.8: minor spelling fix.
No functional change.
2016-05-06 03:11:34 +00:00
Enji Cooper
430f7286a5 Merge ^/user/ngie/release-pkg-fix-tests to unbreak how test files are installed
after r298107

Summary of changes:

- Replace all instances of FILES/TESTS with ${PACKAGE}FILES. This ensures that
  namespacing is kept with FILES appropriately, and that this shouldn't need
  to be repeated if the namespace changes -- only the definition of PACKAGE
  needs to be changed
- Allow PACKAGE to be overridden by callers instead of forcing it to always be
  `tests`. In the event we get to the point where things can be split up
  enough in the base system, it would make more sense to group the tests
  with the blocks they're a part of, e.g. byacc with byacc-tests, etc
- Remove PACKAGE definitions where possible, i.e. where FILES wasn't used
  previously.
- Remove unnecessary TESTSPACKAGE definitions; this has been elided into
  bsd.tests.mk
- Remove unnecessary BINDIRs used previously with ${PACKAGE}FILES;
  ${PACKAGE}FILESDIR is now automatically defined in bsd.test.mk.
- Fix installation of files under data/ subdirectories in lib/libc/tests/hash
  and lib/libc/tests/net/getaddrinfo
- Remove unnecessary .include <bsd.own.mk>s (some opportunistic cleanup)

Document the proposed changes in share/examples/tests/tests/... via examples
so it's clear that ${PACKAGES}FILES is the suggested way forward in terms of
replacing FILES. share/mk/bsd.README didn't seem like the appropriate method
of communicating that info.

MFC after: never probably
X-MFC with: r298107
PR: 209114
Relnotes: yes
Tested with: buildworld, installworld, checkworld; buildworld, packageworld
Sponsored by: EMC / Isilon Storage Division
2016-05-04 23:20:53 +00:00
Alan Somers
8907f744ff Improve performance and functionality of the bitstring(3) api
Two new functions are provided, bit_ffs_at() and bit_ffc_at(), which allow
for efficient searching of set or cleared bits starting from any bit offset
within the bit string.

Performance is improved by operating on longs instead of bytes and using
ffsl() for searches within a long. ffsl() is a compiler builtin in both
clang and gcc for most architectures, converting what was a brute force
while loop search into a couple of instructions.

All of the bitstring(3) API continues to be contained in the header file.
Some of the functions are large enough that perhaps they should be uninlined
and moved to a library, but that is beyond the scope of this commit.

sys/sys/bitstring.h:
        Convert the majority of the existing bit string implementation from
        macros to inline functions.

        Properly protect the implementation from inadvertant macro expansion
        when included in a user's program by prefixing all private
        macros/functions and local variables with '_'.

        Add bit_ffs_at() and bit_ffc_at(). Implement bit_ffs() and
        bit_ffc() in terms of their "at" counterparts.

        Provide a kernel implementation of bit_alloc(), making the full API
        usable in the kernel.

        Improve code documenation.

share/man/man3/bitstring.3:
        Add pre-exisiting API bit_ffc() to the synopsis.

        Document new APIs.

        Document the initialization state of the bit strings
        allocated/declared by bit_alloc() and bit_decl().

        Correct documentation for bitstr_size(). The original code comments
        indicate the size is in bytes, not "elements of bitstr_t". The new
        implementation follows this lead. Only hastd assumed "elements"
        rather than bytes and it has been corrected.

etc/mtree/BSD.tests.dist:
tests/sys/Makefile:
tests/sys/sys/Makefile:
tests/sys/sys/bitstring.c:
        Add tests for all existing and new functionality.

include/bitstring.h
	Include all headers needed by sys/bitstring.h

lib/libbluetooth/bluetooth.h:
usr.sbin/bluetooth/hccontrol/le.c:
        Include bitstring.h instead of sys/bitstring.h.

sbin/hastd/activemap.c:
        Correct usage of bitstr_size().

sys/dev/xen/blkback/blkback.c
        Use new bit_alloc.

sys/kern/subr_unit.c:
        Remove hard-coded assumption that sizeof(bitstr_t) is 1.  Get rid of
        unrb.busy, which caches the number of bits set in unrb.map.  When
        INVARIANTS are disabled, nothing needs to know that information.
        callapse_unr can be adapted to use bit_ffs and bit_ffc instead.
        Eliminating unrb.busy saves memory, simplifies the code, and
        provides a slight speedup when INVARIANTS are disabled.

sys/net/flowtable.c:
        Use the new kernel implementation of bit-alloc, instead of hacking
        the old libc-dependent macro.

sys/sys/param.h
        Update __FreeBSD_version to indicate availability of new API

Submitted by:   gibbs, asomers
Reviewed by:    gibbs, ngie
MFC after:      4 weeks
Sponsored by:   Spectra Logic Corp
Differential Revision:  https://reviews.freebsd.org/D6004
2016-05-04 22:34:11 +00:00
Pedro F. Giffuni
dd3f00cbaf fsck_msdosfs: Adjust a check.
The on-disk FAT array does not include anything before CLUST_FIRST,
compensate in size check.

Obtained from:	NetBSD (CVS Rev. 1.20)
MFC after:	2 weeks
2016-05-04 22:27:22 +00:00
Marcelo Araujo
2c953857dd Use MIN macro from sys/param.h.
MFC after:	2 weeks
2016-05-02 01:40:31 +00:00
Marcelo Araujo
1120faab41 Use MIN/MAX macros from sys/param.h.
MFC after:	2 weeks.
2016-05-02 01:28:21 +00:00
Marcelo Araujo
0193043c46 Use MIN()/MAX() macros from sys/param.h.
Reviewed by:	trasz
MFC after:	2 weeks.
Differential Revision:	https://reviews.freebsd.org/D6118
2016-05-02 00:45:46 +00:00
Marcelo Araujo
e921a133f1 Use MIN() macro from sys/param.h.
Reviewed by:	trasz
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D6119
2016-05-02 00:44:19 +00:00
Pedro F. Giffuni
71a53e69d6 restore: promote some getfiles() parameters to size_t.
This is based on a change from OpenBSD:

"Fix restore so that it can actually restore files larger than 4GB by
changing the type of "size" to off_t in getfiles() plus little dependent
type cleanup, from Daniel Lucq."

It is an important for machines with 32 bit longs.
While here unsign the flags, also from OpenBSD.

Obtained from:	OpenBSD (through bitrig, I hate CVS)
MFC after:	2 weeks
2016-05-01 21:17:30 +00:00
Ed Schouten
e33d251e8e Remove useless calls to basename().
There are a couple of places in the source three where we call
basename() on constant strings. This is bad, because the prototype
standardized by POSIX allows the implementation to use its argument as a
storage buffer.

This change eliminates some of these unportable calls to basename() in
cases where it was only added for cosmetical reasons, namely to trim
argv[0]. There's nothing wrong with setting argv[0] to the full path.

Reviewed by:	jilles
Differential Revision:	https://reviews.freebsd.org/D6093
2016-05-01 08:22:11 +00:00
Pedro F. Giffuni
24229eeb2f restore: fix resource handle leak.
CID:		1007784
MFC after:	5 days
2016-05-01 02:39:39 +00:00
Pedro F. Giffuni
12527d70ac restore: drop casts for calloc(). 2016-05-01 02:31:22 +00:00
Pedro F. Giffuni
f32d2926b0 sbin: ake use of our rounddown() macro when sys/param.h is available.
No functional change.
2016-05-01 02:24:05 +00:00
Pedro F. Giffuni
312717174d sbin: use our howmany() macro when available through <sys/param.h>. 2016-05-01 02:19:49 +00:00
Pedro F. Giffuni
e451cf5f4c restore: fix memory leak.
CID:		272297
MFC after:	5 days
2016-04-30 22:51:09 +00:00
Pedro F. Giffuni
cac8854eb6 restore: use our howmany() instead of reinventing the macro. 2016-04-30 20:05:23 +00:00
Pedro F. Giffuni
fbcfcbbc5b fdisk: drop unused macro and make use of roundup()/rounddown(). 2016-04-30 19:58:54 +00:00
Pedro F. Giffuni
b68ac8007d sbin: minor spelling fixes.
No functional change.
2016-04-30 19:04:59 +00:00
Glen Barber
49dae58b28 Fix including Kyuafile in packaged base system.
Fix a related typo while here.

Note, this change results in the Kyuafile inclusion in the runtime
package, which needs to be fixed, however addresses the PR as far
as I can tell in my tests.

PR:		209114
Submitted by:	ngie
Sponsored by:	The FreeBSD Foundation
2016-04-29 05:28:40 +00:00
Enji Cooper
dc8a83a5b6 Remove logically impossible test in scsidoinquiry(..)
It was already done 4 lines prior and the value of error didn't change

MFC after: 3 days
Reported by: Coverity
CID: 1011236
Sponsored by: EMC / Isilon Storage Division
2016-04-28 21:17:23 +00:00