Revision 5f4fc6d440d77a2cf74fe4ea56955674ac7e35e7 authored by Linus Torvalds on 19 July 2019, 17:06:06 UTC, committed by Linus Torvalds on 19 July 2019, 17:06:06 UTC
Pull networking fixes from David Miller:

 1) Fix AF_XDP cq entry leak, from Ilya Maximets.

 2) Fix handling of PHY power-down on RTL8411B, from Heiner Kallweit.

 3) Add some new PCI IDs to iwlwifi, from Ihab Zhaika.

 4) Fix handling of neigh timers wrt. entries added by userspace, from
    Lorenzo Bianconi.

 5) Various cases of missing of_node_put(), from Nishka Dasgupta.

 6) The new NET_ACT_CT needs to depend upon NF_NAT, from Yue Haibing.

 7) Various RDS layer fixes, from Gerd Rausch.

 8) Fix some more fallout from TCQ_F_CAN_BYPASS generalization, from
    Cong Wang.

 9) Fix FIB source validation checks over loopback, also from Cong Wang.

10) Use promisc for unsupported number of filters, from Justin Chen.

11) Missing sibling route unlink on failure in ipv6, from Ido Schimmel.

* git://git.kernel.org/pub/scm/linux/kernel/git/davem/net: (90 commits)
  tcp: fix tcp_set_congestion_control() use from bpf hook
  ag71xx: fix return value check in ag71xx_probe()
  ag71xx: fix error return code in ag71xx_probe()
  usb: qmi_wwan: add D-Link DWM-222 A2 device ID
  bnxt_en: Fix VNIC accounting when enabling aRFS on 57500 chips.
  net: dsa: sja1105: Fix missing unlock on error in sk_buff()
  gve: replace kfree with kvfree
  selftests/bpf: fix test_xdp_noinline on s390
  selftests/bpf: fix "valid read map access into a read-only array 1" on s390
  net/mlx5: Replace kfree with kvfree
  MAINTAINERS: update netsec driver
  ipv6: Unlink sibling route in case of failure
  liquidio: Replace vmalloc + memset with vzalloc
  udp: Fix typo in net/ipv4/udp.c
  net: bcmgenet: use promisc for unsupported filters
  ipv6: rt6_check should return NULL if 'from' is NULL
  tipc: initialize 'validated' field of received packets
  selftests: add a test case for rp_filter
  fib: relax source validation check for loopback packets
  mlxsw: spectrum: Do not process learned records with a dummy FID
  ...
2 parent s 249be85 + 8d650cd
Raw File
test_strscpy.c
// SPDX-License-Identifier: GPL-2.0+

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/string.h>

#include "../tools/testing/selftests/kselftest_module.h"

/*
 * Kernel module for testing 'strscpy' family of functions.
 */

KSTM_MODULE_GLOBALS();

/*
 * tc() - Run a specific test case.
 * @src: Source string, argument to strscpy_pad()
 * @count: Size of destination buffer, argument to strscpy_pad()
 * @expected: Expected return value from call to strscpy_pad()
 * @terminator: 1 if there should be a terminating null byte 0 otherwise.
 * @chars: Number of characters from the src string expected to be
 *         written to the dst buffer.
 * @pad: Number of pad characters expected (in the tail of dst buffer).
 *       (@pad does not include the null terminator byte.)
 *
 * Calls strscpy_pad() and verifies the return value and state of the
 * destination buffer after the call returns.
 */
static int __init tc(char *src, int count, int expected,
		     int chars, int terminator, int pad)
{
	int nr_bytes_poison;
	int max_expected;
	int max_count;
	int written;
	char buf[6];
	int index, i;
	const char POISON = 'z';

	total_tests++;

	if (!src) {
		pr_err("null source string not supported\n");
		return -1;
	}

	memset(buf, POISON, sizeof(buf));
	/* Future proofing test suite, validate args */
	max_count = sizeof(buf) - 2; /* Space for null and to verify overflow */
	max_expected = count - 1;    /* Space for the null */
	if (count > max_count) {
		pr_err("count (%d) is too big (%d) ... aborting", count, max_count);
		return -1;
	}
	if (expected > max_expected) {
		pr_warn("expected (%d) is bigger than can possibly be returned (%d)",
			expected, max_expected);
	}

	written = strscpy_pad(buf, src, count);
	if ((written) != (expected)) {
		pr_err("%d != %d (written, expected)\n", written, expected);
		goto fail;
	}

	if (count && written == -E2BIG) {
		if (strncmp(buf, src, count - 1) != 0) {
			pr_err("buffer state invalid for -E2BIG\n");
			goto fail;
		}
		if (buf[count - 1] != '\0') {
			pr_err("too big string is not null terminated correctly\n");
			goto fail;
		}
	}

	for (i = 0; i < chars; i++) {
		if (buf[i] != src[i]) {
			pr_err("buf[i]==%c != src[i]==%c\n", buf[i], src[i]);
			goto fail;
		}
	}

	if (terminator) {
		if (buf[count - 1] != '\0') {
			pr_err("string is not null terminated correctly\n");
			goto fail;
		}
	}

	for (i = 0; i < pad; i++) {
		index = chars + terminator + i;
		if (buf[index] != '\0') {
			pr_err("padding missing at index: %d\n", i);
			goto fail;
		}
	}

	nr_bytes_poison = sizeof(buf) - chars - terminator - pad;
	for (i = 0; i < nr_bytes_poison; i++) {
		index = sizeof(buf) - 1 - i; /* Check from the end back */
		if (buf[index] != POISON) {
			pr_err("poison value missing at index: %d\n", i);
			goto fail;
		}
	}

	return 0;
fail:
	failed_tests++;
	return -1;
}

static void __init selftest(void)
{
	/*
	 * tc() uses a destination buffer of size 6 and needs at
	 * least 2 characters spare (one for null and one to check for
	 * overflow).  This means we should only call tc() with
	 * strings up to a maximum of 4 characters long and 'count'
	 * should not exceed 4.  To test with longer strings increase
	 * the buffer size in tc().
	 */

	/* tc(src, count, expected, chars, terminator, pad) */
	KSTM_CHECK_ZERO(tc("a", 0, -E2BIG, 0, 0, 0));
	KSTM_CHECK_ZERO(tc("", 0, -E2BIG, 0, 0, 0));

	KSTM_CHECK_ZERO(tc("a", 1, -E2BIG, 0, 1, 0));
	KSTM_CHECK_ZERO(tc("", 1, 0, 0, 1, 0));

	KSTM_CHECK_ZERO(tc("ab", 2, -E2BIG, 1, 1, 0));
	KSTM_CHECK_ZERO(tc("a", 2, 1, 1, 1, 0));
	KSTM_CHECK_ZERO(tc("", 2, 0, 0, 1, 1));

	KSTM_CHECK_ZERO(tc("abc", 3, -E2BIG, 2, 1, 0));
	KSTM_CHECK_ZERO(tc("ab", 3, 2, 2, 1, 0));
	KSTM_CHECK_ZERO(tc("a", 3, 1, 1, 1, 1));
	KSTM_CHECK_ZERO(tc("", 3, 0, 0, 1, 2));

	KSTM_CHECK_ZERO(tc("abcd", 4, -E2BIG, 3, 1, 0));
	KSTM_CHECK_ZERO(tc("abc", 4, 3, 3, 1, 0));
	KSTM_CHECK_ZERO(tc("ab", 4, 2, 2, 1, 1));
	KSTM_CHECK_ZERO(tc("a", 4, 1, 1, 1, 2));
	KSTM_CHECK_ZERO(tc("", 4, 0, 0, 1, 3));
}

KSTM_MODULE_LOADERS(test_strscpy);
MODULE_AUTHOR("Tobin C. Harding <tobin@kernel.org>");
MODULE_LICENSE("GPL");
back to top