Blame SOURCES/0015-tests-use-tail_alloc-instead-of-calloc-in-bpf-obj_ge.patch

904f19
From 14e5342e996ff122875a2306ba8d84dac096a48a Mon Sep 17 00:00:00 2001
904f19
From: "Dmitry V. Levin" <ldv@altlinux.org>
904f19
Date: Thu, 3 Jan 2019 23:36:22 +0000
904f19
Subject: [PATCH 15/27] tests: use tail_alloc instead of calloc in
904f19
 bpf-obj_get_info_by_fd-prog*
904f19
904f19
This guarantees that map_info and prog_info objects are not accessed
904f19
out of bounds.
904f19
904f19
* tests/bpf-obj_get_info_by_fd.c: Include <string.h>.
904f19
(main): Use tail_alloc instead of calloc for map_info and prog_info.
904f19
904f19
Conflicts:
904f19
	tests/bpf-obj_get_info_by_fd.c
904f19
904f19
Additional changes:
904f19
	tests-m32/bpf-obj_get_info_by_fd.c (copy of tests/bpf-obj_get_info_by_fd.c)
904f19
	tests-mx32/bpf-obj_get_info_by_fd.c (copy of tests/bpf-obj_get_info_by_fd.c)
904f19
904f19
---
904f19
 tests/bpf-obj_get_info_by_fd.c | 7 +++++--
904f19
 1 file changed, 5 insertions(+), 2 deletions(-)
904f19
904f19
Index: strace-4.24/tests/bpf-obj_get_info_by_fd.c
904f19
===================================================================
904f19
--- strace-4.24.orig/tests/bpf-obj_get_info_by_fd.c	2019-03-10 05:19:26.164412164 +0100
904f19
+++ strace-4.24/tests/bpf-obj_get_info_by_fd.c	2019-03-10 05:35:03.618024803 +0100
904f19
@@ -18,6 +18,7 @@
904f19
 #include <stdio.h>
904f19
 #include <stdint.h>
904f19
 #include <stdlib.h>
904f19
+#include <string.h>
904f19
 #include <unistd.h>
904f19
 #include <sys/sysmacros.h>
904f19
 #include <asm/unistd.h>
904f19
@@ -274,13 +275,14 @@
904f19
 	 * initializer element is not constant.
904f19
 	 */
904f19
 	#define  MAP_INFO_SZ (sizeof(*map_info) + 64)
904f19
-	struct bpf_map_info_struct *map_info = calloc(1, MAP_INFO_SZ);
904f19
+	struct bpf_map_info_struct *map_info = tail_alloc(MAP_INFO_SZ);
904f19
 	struct BPF_OBJ_GET_INFO_BY_FD_struct bpf_map_get_info_attr = {
904f19
 		.bpf_fd   = map_fd,
904f19
 		.info_len = MAP_INFO_SZ,
904f19
 		.info     = (uintptr_t) map_info,
904f19
 	};
904f19
 
904f19
+	memset(map_info, 0, MAP_INFO_SZ);
904f19
 	int ret = sys_bpf(BPF_OBJ_GET_INFO_BY_FD, &bpf_map_get_info_attr,
904f19
 			  sizeof(bpf_map_get_info_attr));
904f19
 	if (ret < 0)
904f19
@@ -330,7 +332,7 @@
904f19
 	 * initializer element is not constant.
904f19
 	 */
904f19
 	#define  PROG_INFO_SZ (sizeof(*prog_info) + 64)
904f19
-	struct bpf_prog_info_struct *prog_info = calloc(1, PROG_INFO_SZ);
904f19
+	struct bpf_prog_info_struct *prog_info = tail_alloc(PROG_INFO_SZ);
904f19
 	struct bpf_insn *xlated_prog = tail_alloc(sizeof(*xlated_prog) * 42);
904f19
 	uint32_t *map_ids = tail_alloc(sizeof(*map_ids) * 2);
904f19
 	struct BPF_OBJ_GET_INFO_BY_FD_struct bpf_prog_get_info_attr = {
904f19
@@ -340,6 +342,7 @@
904f19
 	};
904f19
 	size_t old_prog_info_len = PROG_INFO_SZ;
904f19
 
904f19
+	memset(prog_info, 0, PROG_INFO_SZ);
904f19
 	for (unsigned int i = 0; i < 4; i++) {
904f19
 		prog_info->jited_prog_len = 0;
904f19
 		switch (i) {
904f19
Index: strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c
904f19
===================================================================
904f19
--- strace-4.24.orig/tests-m32/bpf-obj_get_info_by_fd.c	2018-06-04 03:11:05.000000000 +0200
904f19
+++ strace-4.24/tests-m32/bpf-obj_get_info_by_fd.c	2019-03-10 05:35:43.934621086 +0100
904f19
@@ -4,27 +4,7 @@
904f19
  * Copyright (c) 2018 The strace developers.
904f19
  * All rights reserved.
904f19
  *
904f19
- * Redistribution and use in source and binary forms, with or without
904f19
- * modification, are permitted provided that the following conditions
904f19
- * are met:
904f19
- * 1. Redistributions of source code must retain the above copyright
904f19
- *    notice, this list of conditions and the following disclaimer.
904f19
- * 2. Redistributions in binary form must reproduce the above copyright
904f19
- *    notice, this list of conditions and the following disclaimer in the
904f19
- *    documentation and/or other materials provided with the distribution.
904f19
- * 3. The name of the author may not be used to endorse or promote products
904f19
- *    derived from this software without specific prior written permission.
904f19
- *
904f19
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
904f19
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
904f19
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
904f19
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
904f19
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
904f19
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
904f19
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
904f19
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
904f19
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
904f19
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
904f19
+ * SPDX-License-Identifier: GPL-2.0-or-later
904f19
  */
904f19
 
904f19
 #include "tests.h"
904f19
@@ -38,6 +18,7 @@
904f19
 #include <stdio.h>
904f19
 #include <stdint.h>
904f19
 #include <stdlib.h>
904f19
+#include <string.h>
904f19
 #include <unistd.h>
904f19
 #include <sys/sysmacros.h>
904f19
 #include <asm/unistd.h>
904f19
@@ -294,13 +275,14 @@
904f19
 	 * initializer element is not constant.
904f19
 	 */
904f19
 	#define  MAP_INFO_SZ (sizeof(*map_info) + 64)
904f19
-	struct bpf_map_info_struct *map_info = calloc(1, MAP_INFO_SZ);
904f19
+	struct bpf_map_info_struct *map_info = tail_alloc(MAP_INFO_SZ);
904f19
 	struct BPF_OBJ_GET_INFO_BY_FD_struct bpf_map_get_info_attr = {
904f19
 		.bpf_fd   = map_fd,
904f19
 		.info_len = MAP_INFO_SZ,
904f19
 		.info     = (uintptr_t) map_info,
904f19
 	};
904f19
 
904f19
+	memset(map_info, 0, MAP_INFO_SZ);
904f19
 	int ret = sys_bpf(BPF_OBJ_GET_INFO_BY_FD, &bpf_map_get_info_attr,
904f19
 			  sizeof(bpf_map_get_info_attr));
904f19
 	if (ret < 0)
904f19
@@ -350,7 +332,7 @@
904f19
 	 * initializer element is not constant.
904f19
 	 */
904f19
 	#define  PROG_INFO_SZ (sizeof(*prog_info) + 64)
904f19
-	struct bpf_prog_info_struct *prog_info = calloc(1, PROG_INFO_SZ);
904f19
+	struct bpf_prog_info_struct *prog_info = tail_alloc(PROG_INFO_SZ);
904f19
 	struct bpf_insn *xlated_prog = tail_alloc(sizeof(*xlated_prog) * 42);
904f19
 	uint32_t *map_ids = tail_alloc(sizeof(*map_ids) * 2);
904f19
 	struct BPF_OBJ_GET_INFO_BY_FD_struct bpf_prog_get_info_attr = {
904f19
@@ -360,6 +342,7 @@
904f19
 	};
904f19
 	size_t old_prog_info_len = PROG_INFO_SZ;
904f19
 
904f19
+	memset(prog_info, 0, PROG_INFO_SZ);
904f19
 	for (unsigned int i = 0; i < 4; i++) {
904f19
 		prog_info->jited_prog_len = 0;
904f19
 		switch (i) {
904f19
Index: strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c
904f19
===================================================================
904f19
--- strace-4.24.orig/tests-mx32/bpf-obj_get_info_by_fd.c	2018-06-04 03:11:05.000000000 +0200
904f19
+++ strace-4.24/tests-mx32/bpf-obj_get_info_by_fd.c	2019-03-10 05:35:48.837571989 +0100
904f19
@@ -4,27 +4,7 @@
904f19
  * Copyright (c) 2018 The strace developers.
904f19
  * All rights reserved.
904f19
  *
904f19
- * Redistribution and use in source and binary forms, with or without
904f19
- * modification, are permitted provided that the following conditions
904f19
- * are met:
904f19
- * 1. Redistributions of source code must retain the above copyright
904f19
- *    notice, this list of conditions and the following disclaimer.
904f19
- * 2. Redistributions in binary form must reproduce the above copyright
904f19
- *    notice, this list of conditions and the following disclaimer in the
904f19
- *    documentation and/or other materials provided with the distribution.
904f19
- * 3. The name of the author may not be used to endorse or promote products
904f19
- *    derived from this software without specific prior written permission.
904f19
- *
904f19
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
904f19
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
904f19
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
904f19
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
904f19
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
904f19
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
904f19
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
904f19
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
904f19
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
904f19
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
904f19
+ * SPDX-License-Identifier: GPL-2.0-or-later
904f19
  */
904f19
 
904f19
 #include "tests.h"
904f19
@@ -38,6 +18,7 @@
904f19
 #include <stdio.h>
904f19
 #include <stdint.h>
904f19
 #include <stdlib.h>
904f19
+#include <string.h>
904f19
 #include <unistd.h>
904f19
 #include <sys/sysmacros.h>
904f19
 #include <asm/unistd.h>
904f19
@@ -294,13 +275,14 @@
904f19
 	 * initializer element is not constant.
904f19
 	 */
904f19
 	#define  MAP_INFO_SZ (sizeof(*map_info) + 64)
904f19
-	struct bpf_map_info_struct *map_info = calloc(1, MAP_INFO_SZ);
904f19
+	struct bpf_map_info_struct *map_info = tail_alloc(MAP_INFO_SZ);
904f19
 	struct BPF_OBJ_GET_INFO_BY_FD_struct bpf_map_get_info_attr = {
904f19
 		.bpf_fd   = map_fd,
904f19
 		.info_len = MAP_INFO_SZ,
904f19
 		.info     = (uintptr_t) map_info,
904f19
 	};
904f19
 
904f19
+	memset(map_info, 0, MAP_INFO_SZ);
904f19
 	int ret = sys_bpf(BPF_OBJ_GET_INFO_BY_FD, &bpf_map_get_info_attr,
904f19
 			  sizeof(bpf_map_get_info_attr));
904f19
 	if (ret < 0)
904f19
@@ -350,7 +332,7 @@
904f19
 	 * initializer element is not constant.
904f19
 	 */
904f19
 	#define  PROG_INFO_SZ (sizeof(*prog_info) + 64)
904f19
-	struct bpf_prog_info_struct *prog_info = calloc(1, PROG_INFO_SZ);
904f19
+	struct bpf_prog_info_struct *prog_info = tail_alloc(PROG_INFO_SZ);
904f19
 	struct bpf_insn *xlated_prog = tail_alloc(sizeof(*xlated_prog) * 42);
904f19
 	uint32_t *map_ids = tail_alloc(sizeof(*map_ids) * 2);
904f19
 	struct BPF_OBJ_GET_INFO_BY_FD_struct bpf_prog_get_info_attr = {
904f19
@@ -360,6 +342,7 @@
904f19
 	};
904f19
 	size_t old_prog_info_len = PROG_INFO_SZ;
904f19
 
904f19
+	memset(prog_info, 0, PROG_INFO_SZ);
904f19
 	for (unsigned int i = 0; i < 4; i++) {
904f19
 		prog_info->jited_prog_len = 0;
904f19
 		switch (i) {