aboutsummaryrefslogtreecommitdiffstats
path: root/testing/zfs-grsec/0002-Add-support-for-libtirpc.patch
blob: 1a44c757b47d6770ef53dbd1b1ef86c66c26d1c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
From 0f29fd8ac81a166103f311c180fd06d956dc6dc4 Mon Sep 17 00:00:00 2001
From: Carlo Landmeter <clandmeter@gmail.com>
Date: Tue, 1 Mar 2016 15:13:44 +0100
Subject: [PATCH 2/8] Add support for libtirpc

This introduces the --with-tirpc configure switch to compile with libtirpc.
This is needed for libc's which do not have their own RPC libary (ie musl libc).
---
 cmd/mount_zfs/Makefile.am    |  3 ++-
 cmd/zdb/Makefile.am          |  2 +-
 cmd/zed/Makefile.am          |  3 ++-
 cmd/zfs/Makefile.am          |  2 +-
 cmd/zhack/Makefile.am        |  2 +-
 cmd/zinject/Makefile.am      |  3 ++-
 cmd/zpool/Makefile.am        |  2 +-
 cmd/zstreamdump/Makefile.am  |  2 +-
 cmd/ztest/Makefile.am        |  2 +-
 config/tirpc.m4              | 17 +++++++++++++++++
 config/user.m4               |  1 +
 lib/libnvpair/Makefile.am    |  2 +-
 lib/libspl/Makefile.am       |  6 +++---
 lib/libspl/include/rpc/xdr.h |  2 ++
 lib/libspl/xdr.c             |  2 ++
 module/nvpair/nvpair.c       |  4 ++++
 16 files changed, 42 insertions(+), 13 deletions(-)
 create mode 100644 config/tirpc.m4

diff --git a/cmd/mount_zfs/Makefile.am b/cmd/mount_zfs/Makefile.am
index b1d9389..4be1135 100644
--- a/cmd/mount_zfs/Makefile.am
+++ b/cmd/mount_zfs/Makefile.am
@@ -19,4 +19,5 @@ mount_zfs_LDADD = \
 	$(top_builddir)/lib/libuutil/libuutil.la \
 	$(top_builddir)/lib/libzpool/libzpool.la \
 	$(top_builddir)/lib/libzfs/libzfs.la \
-	$(top_builddir)/lib/libzfs_core/libzfs_core.la
+	$(top_builddir)/lib/libzfs_core/libzfs_core.la \
+	$(TIRPC_LIBS)
diff --git a/cmd/zdb/Makefile.am b/cmd/zdb/Makefile.am
index c22186a..181a821 100644
--- a/cmd/zdb/Makefile.am
+++ b/cmd/zdb/Makefile.am
@@ -19,4 +19,4 @@ zdb_LDADD = \
 	$(top_builddir)/lib/libzfs/libzfs.la \
 	$(top_builddir)/lib/libzfs_core/libzfs_core.la
 
-zdb_LDADD += $(ZLIB)
+zdb_LDADD += $(ZLIB) $(TIRPC_LIBS)
diff --git a/cmd/zed/Makefile.am b/cmd/zed/Makefile.am
index 70e4f7f..ce16ceb 100644
--- a/cmd/zed/Makefile.am
+++ b/cmd/zed/Makefile.am
@@ -30,7 +30,8 @@ zed_LDADD = \
 	$(top_builddir)/lib/libspl/libspl.la \
 	$(top_builddir)/lib/libzpool/libzpool.la \
 	$(top_builddir)/lib/libzfs/libzfs.la \
-	$(top_builddir)/lib/libzfs_core/libzfs_core.la
+	$(top_builddir)/lib/libzfs_core/libzfs_core.la \
+	$(TIRPC_LIBS)
 
 zedconfdir = $(sysconfdir)/zfs/zed.d
 
diff --git a/cmd/zfs/Makefile.am b/cmd/zfs/Makefile.am
index 3cac73d..ea35555 100644
--- a/cmd/zfs/Makefile.am
+++ b/cmd/zfs/Makefile.am
@@ -19,5 +19,5 @@ zfs_LDADD = \
 	$(top_builddir)/lib/libzfs/libzfs.la \
 	$(top_builddir)/lib/libzfs_core/libzfs_core.la
 
-zfs_LDADD += $(ZLIB)
+zfs_LDADD += $(ZLIB) $(TIRPC_LIBS)
 zfs_LDFLAGS = -pthread
diff --git a/cmd/zhack/Makefile.am b/cmd/zhack/Makefile.am
index 53e3241..07b5fab 100644
--- a/cmd/zhack/Makefile.am
+++ b/cmd/zhack/Makefile.am
@@ -16,4 +16,4 @@ zhack_LDADD = \
 	$(top_builddir)/lib/libzfs/libzfs.la \
 	$(top_builddir)/lib/libzfs_core/libzfs_core.la
 
-zhack_LDADD += $(ZLIB)
+zhack_LDADD += $(ZLIB) $(TIRPC_LIBS)
diff --git a/cmd/zinject/Makefile.am b/cmd/zinject/Makefile.am
index 2500bee..2d069d3 100644
--- a/cmd/zinject/Makefile.am
+++ b/cmd/zinject/Makefile.am
@@ -16,4 +16,5 @@ zinject_LDADD = \
 	$(top_builddir)/lib/libuutil/libuutil.la \
 	$(top_builddir)/lib/libzpool/libzpool.la \
 	$(top_builddir)/lib/libzfs/libzfs.la \
-	$(top_builddir)/lib/libzfs_core/libzfs_core.la
+	$(top_builddir)/lib/libzfs_core/libzfs_core.la \
+	$(TIRPC_LIBS)
diff --git a/cmd/zpool/Makefile.am b/cmd/zpool/Makefile.am
index c11951b..a59bf32 100644
--- a/cmd/zpool/Makefile.am
+++ b/cmd/zpool/Makefile.am
@@ -19,4 +19,4 @@ zpool_LDADD = \
 	$(top_builddir)/lib/libzpool/libzpool.la \
 	$(top_builddir)/lib/libzfs/libzfs.la \
 	$(top_builddir)/lib/libzfs_core/libzfs_core.la \
-	$(LIBBLKID)
+	$(LIBBLKID) $(TIRPC_LIBS)
diff --git a/cmd/zstreamdump/Makefile.am b/cmd/zstreamdump/Makefile.am
index 654863a..f800a8e 100644
--- a/cmd/zstreamdump/Makefile.am
+++ b/cmd/zstreamdump/Makefile.am
@@ -16,4 +16,4 @@ zstreamdump_LDADD = \
 	$(top_builddir)/lib/libzfs/libzfs.la \
 	$(top_builddir)/lib/libzfs_core/libzfs_core.la
 
-zstreamdump_LDADD += $(ZLIB)
+zstreamdump_LDADD += $(ZLIB) $(TIRPC_LIBS)
diff --git a/cmd/ztest/Makefile.am b/cmd/ztest/Makefile.am
index e3be39a..1953fe8 100644
--- a/cmd/ztest/Makefile.am
+++ b/cmd/ztest/Makefile.am
@@ -19,4 +19,4 @@ ztest_LDADD = \
 	$(top_builddir)/lib/libzfs/libzfs.la \
 	$(top_builddir)/lib/libzfs_core/libzfs_core.la
 
-ztest_LDADD += -lm -ldl
+ztest_LDADD += -lm -ldl $(TIRPC_LIBS)
diff --git a/config/tirpc.m4 b/config/tirpc.m4
new file mode 100644
index 0000000..ec15785
--- /dev/null
+++ b/config/tirpc.m4
@@ -0,0 +1,17 @@
+dnl
+dnl musl support
+dnl
+
+AC_DEFUN([ZFS_AC_CONFIG_USER_TIRPC], [
+AH_TEMPLATE([WITH_TIRPC],
+  [Define to 1 if libtirpc is being used as the RPC library])
+AC_ARG_WITH(tirpc,
+AC_HELP_STRING([--with-tirpc], [compile with libtirpc]),
+[if test x$withval = xyes; then
+  AC_DEFINE([WITH_TIRPC], 1, [Define if you have musl])
+  PKG_CHECK_MODULES([TIRPC],[libtirpc])
+  AC_DEFINE([WITH_TIRPC], 1, [Define if you have libtirpc])
+  AC_SUBST(TIRPC_CFLAGS)
+  AC_SUBST(TIRPC_LIBS)
+fi])
+])
diff --git a/config/user.m4 b/config/user.m4
index 7f79420..820b8d3 100644
--- a/config/user.m4
+++ b/config/user.m4
@@ -13,6 +13,7 @@ AC_DEFUN([ZFS_AC_CONFIG_USER], [
 	ZFS_AC_CONFIG_USER_LIBBLKID
 	ZFS_AC_CONFIG_USER_FRAME_LARGER_THAN
 	ZFS_AC_CONFIG_USER_RUNSTATEDIR
+	ZFS_AC_CONFIG_USER_TIRPC
 dnl #
 dnl #	Checks for library functions
 	AC_CHECK_FUNCS([mlockall])
diff --git a/lib/libnvpair/Makefile.am b/lib/libnvpair/Makefile.am
index c9ac1f1..985285a 100644
--- a/lib/libnvpair/Makefile.am
+++ b/lib/libnvpair/Makefile.am
@@ -4,7 +4,7 @@ VPATH = \
 	$(top_srcdir)/module/nvpair \
 	$(top_srcdir)/lib/libnvpair
 
-AM_CFLAGS += $(DEBUG_STACKFLAGS) $(FRAME_LARGER_THAN)
+AM_CFLAGS += $(DEBUG_STACKFLAGS) $(FRAME_LARGER_THAN) $(TIRPC_CFLAGS)
 
 DEFAULT_INCLUDES += \
 	-I$(top_srcdir)/include \
diff --git a/lib/libspl/Makefile.am b/lib/libspl/Makefile.am
index a569446..9cedfaa 100644
--- a/lib/libspl/Makefile.am
+++ b/lib/libspl/Makefile.am
@@ -4,13 +4,13 @@ VPATH = \
 	$(top_srcdir)/lib/libspl \
 	$(top_srcdir)/lib/libspl/$(TARGET_ASM_DIR)
 
-AM_CFLAGS += $(DEBUG_STACKFLAGS) $(FRAME_LARGER_THAN)
+AM_CFLAGS += $(DEBUG_STACKFLAGS) $(FRAME_LARGER_THAN) $(TIRPC_CFLAGS)
 
 SUBDIRS = include $(TARGET_ASM_DIR)
 DIST_SUBDIRS = include asm-generic asm-i386 asm-x86_64
 
 DEFAULT_INCLUDES += \
-	-I$(top_srcdir)/lib/libspl/include
+	-I$(top_srcdir)/lib/libspl/include $(TIRPC_CFLAGS)
 
 AM_CCASFLAGS = \
 	-I$(top_srcdir)/lib/libspl/include
@@ -42,6 +42,6 @@ nodist_libspl_la_SOURCES = \
 	$(USER_ASM) \
 	$(KERNEL_C)
 
-libspl_la_LIBADD = -lrt
+libspl_la_LIBADD = -lrt $(TIRPC_LDFLAGS)
 
 EXTRA_DIST = $(USER_C)
diff --git a/lib/libspl/include/rpc/xdr.h b/lib/libspl/include/rpc/xdr.h
index 99500d6..cd2d17a 100644
--- a/lib/libspl/include/rpc/xdr.h
+++ b/lib/libspl/include/rpc/xdr.h
@@ -60,6 +60,8 @@ typedef struct xdr_bytesrec {
 #define	XDR_RDMAGET	4
 #define	XDR_RDMASET	5
 
+#ifndef WITH_TIRPC
 extern bool_t xdr_control(XDR *xdrs, int request, void *info);
+#endif
 
 #endif
diff --git a/lib/libspl/xdr.c b/lib/libspl/xdr.c
index 288a338..f122496 100644
--- a/lib/libspl/xdr.c
+++ b/lib/libspl/xdr.c
@@ -29,6 +29,7 @@
  * under license from the Regents of the University of California.
  */
 
+#ifndef WITH_TIRPC
 #include <rpc/xdr.h>
 
 /*
@@ -76,3 +77,4 @@ xdr_control(XDR *xdrs, int request, void *info)
 	}
 	return (FALSE);
 }
+#endif
diff --git a/module/nvpair/nvpair.c b/module/nvpair/nvpair.c
index 1eca0fe..efd6287 100644
--- a/module/nvpair/nvpair.c
+++ b/module/nvpair/nvpair.c
@@ -3251,8 +3251,12 @@ nvs_xdr_nvpair(nvstream_t *nvs, nvpair_t *nvp, size_t *size)
 			return (0);
 
 		/* sanity check the size parameter */
+#ifndef WITH_TIRPC
 		if (!xdr_control(xdr, XDR_GET_BYTES_AVAIL, &bytesrec))
 			return (EFAULT);
+#else
+		xdr_control(xdr, XDR_GET_BYTES_AVAIL, &bytesrec);
+#endif
 
 		if (*size > NVS_XDR_MAX_LEN(bytesrec.xc_num_avail))
 			return (EFAULT);
-- 
2.7.2