summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKhem Raj <raj.khem@gmail.com>2022-08-14 15:20:34 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-08-16 14:57:58 +0100
commitdf6a394282c6df3a361d5b72c7bcb9e6f61241a1 (patch)
tree9a0754d110549ce483038c742ae766a1e5f4baa0
parent61929f05d78553b9759d15f88ba8fda5accafd1b (diff)
downloadpoky-df6a394282c6df3a361d5b72c7bcb9e6f61241a1.tar.gz
libtirpc: Backport fix for CVE-2021-46828
CVE: CVE-2021-46828 (From OE-Core rev: a4fb608f7fba5b441074505f09b9a9a405884463) Signed-off-by: Khem Raj <raj.khem@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-extended/libtirpc/libtirpc/CVE-2021-46828.patch565
-rw-r--r--meta/recipes-extended/libtirpc/libtirpc_1.3.2.bb4
2 files changed, 568 insertions, 1 deletions
diff --git a/meta/recipes-extended/libtirpc/libtirpc/CVE-2021-46828.patch b/meta/recipes-extended/libtirpc/libtirpc/CVE-2021-46828.patch
new file mode 100644
index 0000000000..64dffb923b
--- /dev/null
+++ b/meta/recipes-extended/libtirpc/libtirpc/CVE-2021-46828.patch
@@ -0,0 +1,565 @@
1From 86529758570cef4c73fb9b9c4104fdc510f701ed Mon Sep 17 00:00:00 2001
2From: Dai Ngo <dai.ngo@oracle.com>
3Date: Sat, 21 Aug 2021 13:16:23 -0400
4Subject: [PATCH] Fix DoS vulnerability in libtirpc
5
6Currently svc_run does not handle poll timeout and rendezvous_request
7does not handle EMFILE error returned from accept(2 as it used to.
8These two missing functionality were removed by commit b2c9430f46c4.
9
10The effect of not handling poll timeout allows idle TCP conections
11to remain ESTABLISHED indefinitely. When the number of connections
12reaches the limit of the open file descriptors (ulimit -n) then
13accept(2) fails with EMFILE. Since there is no handling of EMFILE
14error this causes svc_run() to get in a tight loop calling accept(2).
15This resulting in the RPC service of svc_run is being down, it's
16no longer able to service any requests.
17
18RPC service rpcbind, statd and mountd are effected by this
19problem.
20
21Fix by enhancing rendezvous_request to keep the number of
22SVCXPRT conections to 4/5 of the size of the file descriptor
23table. When this thresold is reached, it destroys the idle
24TCP connections or destroys the least active connection if
25no idle connnction was found.
26
27Fixes: 44bf15b8 rpcbind: don't use obsolete svc_fdset interface of libtirpc
28
29CVE: CVE-2021-46828
30Upstream-Status: Backport [http://git.linux-nfs.org/?p=steved/libtirpc.git;a=commit;h=86529758570cef4c73fb9b9c4104fdc510f701ed]
31Signed-off-by: dai.ngo@oracle.com
32Signed-off-by: Steve Dickson <steved@redhat.com>
33---
34 INSTALL | 371 +----------------------------------------------------------
35 src/svc.c | 17 ++-
36 src/svc_vc.c | 62 +++++++++-
37 3 files changed, 78 insertions(+), 372 deletions(-)
38 mode change 100644 => 120000 INSTALL
39
40diff --git a/INSTALL b/INSTALL
41deleted file mode 100644
42index 2099840..0000000
43--- a/INSTALL
44+++ /dev/null
45@@ -1,370 +0,0 @@
46-Installation Instructions
47-*************************
48-
49-Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation,
50-Inc.
51-
52- Copying and distribution of this file, with or without modification,
53-are permitted in any medium without royalty provided the copyright
54-notice and this notice are preserved. This file is offered as-is,
55-without warranty of any kind.
56-
57-Basic Installation
58-==================
59-
60- Briefly, the shell command `./configure && make && make install'
61-should configure, build, and install this package. The following
62-more-detailed instructions are generic; see the `README' file for
63-instructions specific to this package. Some packages provide this
64-`INSTALL' file but do not implement all of the features documented
65-below. The lack of an optional feature in a given package is not
66-necessarily a bug. More recommendations for GNU packages can be found
67-in *note Makefile Conventions: (standards)Makefile Conventions.
68-
69- The `configure' shell script attempts to guess correct values for
70-various system-dependent variables used during compilation. It uses
71-those values to create a `Makefile' in each directory of the package.
72-It may also create one or more `.h' files containing system-dependent
73-definitions. Finally, it creates a shell script `config.status' that
74-you can run in the future to recreate the current configuration, and a
75-file `config.log' containing compiler output (useful mainly for
76-debugging `configure').
77-
78- It can also use an optional file (typically called `config.cache'
79-and enabled with `--cache-file=config.cache' or simply `-C') that saves
80-the results of its tests to speed up reconfiguring. Caching is
81-disabled by default to prevent problems with accidental use of stale
82-cache files.
83-
84- If you need to do unusual things to compile the package, please try
85-to figure out how `configure' could check whether to do them, and mail
86-diffs or instructions to the address given in the `README' so they can
87-be considered for the next release. If you are using the cache, and at
88-some point `config.cache' contains results you don't want to keep, you
89-may remove or edit it.
90-
91- The file `configure.ac' (or `configure.in') is used to create
92-`configure' by a program called `autoconf'. You need `configure.ac' if
93-you want to change it or regenerate `configure' using a newer version
94-of `autoconf'.
95-
96- The simplest way to compile this package is:
97-
98- 1. `cd' to the directory containing the package's source code and type
99- `./configure' to configure the package for your system.
100-
101- Running `configure' might take a while. While running, it prints
102- some messages telling which features it is checking for.
103-
104- 2. Type `make' to compile the package.
105-
106- 3. Optionally, type `make check' to run any self-tests that come with
107- the package, generally using the just-built uninstalled binaries.
108-
109- 4. Type `make install' to install the programs and any data files and
110- documentation. When installing into a prefix owned by root, it is
111- recommended that the package be configured and built as a regular
112- user, and only the `make install' phase executed with root
113- privileges.
114-
115- 5. Optionally, type `make installcheck' to repeat any self-tests, but
116- this time using the binaries in their final installed location.
117- This target does not install anything. Running this target as a
118- regular user, particularly if the prior `make install' required
119- root privileges, verifies that the installation completed
120- correctly.
121-
122- 6. You can remove the program binaries and object files from the
123- source code directory by typing `make clean'. To also remove the
124- files that `configure' created (so you can compile the package for
125- a different kind of computer), type `make distclean'. There is
126- also a `make maintainer-clean' target, but that is intended mainly
127- for the package's developers. If you use it, you may have to get
128- all sorts of other programs in order to regenerate files that came
129- with the distribution.
130-
131- 7. Often, you can also type `make uninstall' to remove the installed
132- files again. In practice, not all packages have tested that
133- uninstallation works correctly, even though it is required by the
134- GNU Coding Standards.
135-
136- 8. Some packages, particularly those that use Automake, provide `make
137- distcheck', which can by used by developers to test that all other
138- targets like `make install' and `make uninstall' work correctly.
139- This target is generally not run by end users.
140-
141-Compilers and Options
142-=====================
143-
144- Some systems require unusual options for compilation or linking that
145-the `configure' script does not know about. Run `./configure --help'
146-for details on some of the pertinent environment variables.
147-
148- You can give `configure' initial values for configuration parameters
149-by setting variables in the command line or in the environment. Here
150-is an example:
151-
152- ./configure CC=c99 CFLAGS=-g LIBS=-lposix
153-
154- *Note Defining Variables::, for more details.
155-
156-Compiling For Multiple Architectures
157-====================================
158-
159- You can compile the package for more than one kind of computer at the
160-same time, by placing the object files for each architecture in their
161-own directory. To do this, you can use GNU `make'. `cd' to the
162-directory where you want the object files and executables to go and run
163-the `configure' script. `configure' automatically checks for the
164-source code in the directory that `configure' is in and in `..'. This
165-is known as a "VPATH" build.
166-
167- With a non-GNU `make', it is safer to compile the package for one
168-architecture at a time in the source code directory. After you have
169-installed the package for one architecture, use `make distclean' before
170-reconfiguring for another architecture.
171-
172- On MacOS X 10.5 and later systems, you can create libraries and
173-executables that work on multiple system types--known as "fat" or
174-"universal" binaries--by specifying multiple `-arch' options to the
175-compiler but only a single `-arch' option to the preprocessor. Like
176-this:
177-
178- ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
179- CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
180- CPP="gcc -E" CXXCPP="g++ -E"
181-
182- This is not guaranteed to produce working output in all cases, you
183-may have to build one architecture at a time and combine the results
184-using the `lipo' tool if you have problems.
185-
186-Installation Names
187-==================
188-
189- By default, `make install' installs the package's commands under
190-`/usr/local/bin', include files under `/usr/local/include', etc. You
191-can specify an installation prefix other than `/usr/local' by giving
192-`configure' the option `--prefix=PREFIX', where PREFIX must be an
193-absolute file name.
194-
195- You can specify separate installation prefixes for
196-architecture-specific files and architecture-independent files. If you
197-pass the option `--exec-prefix=PREFIX' to `configure', the package uses
198-PREFIX as the prefix for installing programs and libraries.
199-Documentation and other data files still use the regular prefix.
200-
201- In addition, if you use an unusual directory layout you can give
202-options like `--bindir=DIR' to specify different values for particular
203-kinds of files. Run `configure --help' for a list of the directories
204-you can set and what kinds of files go in them. In general, the
205-default for these options is expressed in terms of `${prefix}', so that
206-specifying just `--prefix' will affect all of the other directory
207-specifications that were not explicitly provided.
208-
209- The most portable way to affect installation locations is to pass the
210-correct locations to `configure'; however, many packages provide one or
211-both of the following shortcuts of passing variable assignments to the
212-`make install' command line to change installation locations without
213-having to reconfigure or recompile.
214-
215- The first method involves providing an override variable for each
216-affected directory. For example, `make install
217-prefix=/alternate/directory' will choose an alternate location for all
218-directory configuration variables that were expressed in terms of
219-`${prefix}'. Any directories that were specified during `configure',
220-but not in terms of `${prefix}', must each be overridden at install
221-time for the entire installation to be relocated. The approach of
222-makefile variable overrides for each directory variable is required by
223-the GNU Coding Standards, and ideally causes no recompilation.
224-However, some platforms have known limitations with the semantics of
225-shared libraries that end up requiring recompilation when using this
226-method, particularly noticeable in packages that use GNU Libtool.
227-
228- The second method involves providing the `DESTDIR' variable. For
229-example, `make install DESTDIR=/alternate/directory' will prepend
230-`/alternate/directory' before all installation names. The approach of
231-`DESTDIR' overrides is not required by the GNU Coding Standards, and
232-does not work on platforms that have drive letters. On the other hand,
233-it does better at avoiding recompilation issues, and works well even
234-when some directory options were not specified in terms of `${prefix}'
235-at `configure' time.
236-
237-Optional Features
238-=================
239-
240- If the package supports it, you can cause programs to be installed
241-with an extra prefix or suffix on their names by giving `configure' the
242-option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
243-
244- Some packages pay attention to `--enable-FEATURE' options to
245-`configure', where FEATURE indicates an optional part of the package.
246-They may also pay attention to `--with-PACKAGE' options, where PACKAGE
247-is something like `gnu-as' or `x' (for the X Window System). The
248-`README' should mention any `--enable-' and `--with-' options that the
249-package recognizes.
250-
251- For packages that use the X Window System, `configure' can usually
252-find the X include and library files automatically, but if it doesn't,
253-you can use the `configure' options `--x-includes=DIR' and
254-`--x-libraries=DIR' to specify their locations.
255-
256- Some packages offer the ability to configure how verbose the
257-execution of `make' will be. For these packages, running `./configure
258---enable-silent-rules' sets the default to minimal output, which can be
259-overridden with `make V=1'; while running `./configure
260---disable-silent-rules' sets the default to verbose, which can be
261-overridden with `make V=0'.
262-
263-Particular systems
264-==================
265-
266- On HP-UX, the default C compiler is not ANSI C compatible. If GNU
267-CC is not installed, it is recommended to use the following options in
268-order to use an ANSI C compiler:
269-
270- ./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
271-
272-and if that doesn't work, install pre-built binaries of GCC for HP-UX.
273-
274- HP-UX `make' updates targets which have the same time stamps as
275-their prerequisites, which makes it generally unusable when shipped
276-generated files such as `configure' are involved. Use GNU `make'
277-instead.
278-
279- On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
280-parse its `<wchar.h>' header file. The option `-nodtk' can be used as
281-a workaround. If GNU CC is not installed, it is therefore recommended
282-to try
283-
284- ./configure CC="cc"
285-
286-and if that doesn't work, try
287-
288- ./configure CC="cc -nodtk"
289-
290- On Solaris, don't put `/usr/ucb' early in your `PATH'. This
291-directory contains several dysfunctional programs; working variants of
292-these programs are available in `/usr/bin'. So, if you need `/usr/ucb'
293-in your `PATH', put it _after_ `/usr/bin'.
294-
295- On Haiku, software installed for all users goes in `/boot/common',
296-not `/usr/local'. It is recommended to use the following options:
297-
298- ./configure --prefix=/boot/common
299-
300-Specifying the System Type
301-==========================
302-
303- There may be some features `configure' cannot figure out
304-automatically, but needs to determine by the type of machine the package
305-will run on. Usually, assuming the package is built to be run on the
306-_same_ architectures, `configure' can figure that out, but if it prints
307-a message saying it cannot guess the machine type, give it the
308-`--build=TYPE' option. TYPE can either be a short name for the system
309-type, such as `sun4', or a canonical name which has the form:
310-
311- CPU-COMPANY-SYSTEM
312-
313-where SYSTEM can have one of these forms:
314-
315- OS
316- KERNEL-OS
317-
318- See the file `config.sub' for the possible values of each field. If
319-`config.sub' isn't included in this package, then this package doesn't
320-need to know the machine type.
321-
322- If you are _building_ compiler tools for cross-compiling, you should
323-use the option `--target=TYPE' to select the type of system they will
324-produce code for.
325-
326- If you want to _use_ a cross compiler, that generates code for a
327-platform different from the build platform, you should specify the
328-"host" platform (i.e., that on which the generated programs will
329-eventually be run) with `--host=TYPE'.
330-
331-Sharing Defaults
332-================
333-
334- If you want to set default values for `configure' scripts to share,
335-you can create a site shell script called `config.site' that gives
336-default values for variables like `CC', `cache_file', and `prefix'.
337-`configure' looks for `PREFIX/share/config.site' if it exists, then
338-`PREFIX/etc/config.site' if it exists. Or, you can set the
339-`CONFIG_SITE' environment variable to the location of the site script.
340-A warning: not all `configure' scripts look for a site script.
341-
342-Defining Variables
343-==================
344-
345- Variables not defined in a site shell script can be set in the
346-environment passed to `configure'. However, some packages may run
347-configure again during the build, and the customized values of these
348-variables may be lost. In order to avoid this problem, you should set
349-them in the `configure' command line, using `VAR=value'. For example:
350-
351- ./configure CC=/usr/local2/bin/gcc
352-
353-causes the specified `gcc' to be used as the C compiler (unless it is
354-overridden in the site shell script).
355-
356-Unfortunately, this technique does not work for `CONFIG_SHELL' due to
357-an Autoconf limitation. Until the limitation is lifted, you can use
358-this workaround:
359-
360- CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash
361-
362-`configure' Invocation
363-======================
364-
365- `configure' recognizes the following options to control how it
366-operates.
367-
368-`--help'
369-`-h'
370- Print a summary of all of the options to `configure', and exit.
371-
372-`--help=short'
373-`--help=recursive'
374- Print a summary of the options unique to this package's
375- `configure', and exit. The `short' variant lists options used
376- only in the top level, while the `recursive' variant lists options
377- also present in any nested packages.
378-
379-`--version'
380-`-V'
381- Print the version of Autoconf used to generate the `configure'
382- script, and exit.
383-
384-`--cache-file=FILE'
385- Enable the cache: use and save the results of the tests in FILE,
386- traditionally `config.cache'. FILE defaults to `/dev/null' to
387- disable caching.
388-
389-`--config-cache'
390-`-C'
391- Alias for `--cache-file=config.cache'.
392-
393-`--quiet'
394-`--silent'
395-`-q'
396- Do not print messages saying which checks are being made. To
397- suppress all normal output, redirect it to `/dev/null' (any error
398- messages will still be shown).
399-
400-`--srcdir=DIR'
401- Look for the package's source code in directory DIR. Usually
402- `configure' can determine that directory automatically.
403-
404-`--prefix=DIR'
405- Use DIR as the installation prefix. *note Installation Names::
406- for more details, including other options available for fine-tuning
407- the installation locations.
408-
409-`--no-create'
410-`-n'
411- Run the configure checks, but stop before creating any output
412- files.
413-
414-`configure' also accepts some other, not widely useful, options. Run
415-`configure --help' for more details.
416diff --git a/INSTALL b/INSTALL
417new file mode 120000
418index 0000000..e3f22c0
419--- /dev/null
420+++ b/INSTALL
421@@ -0,0 +1 @@
422+/usr/share/automake-1.16/INSTALL
423\ No newline at end of file
424diff --git a/src/svc.c b/src/svc.c
425index 6db164b..3a8709f 100644
426--- a/src/svc.c
427+++ b/src/svc.c
428@@ -57,7 +57,7 @@
429
430 #define max(a, b) (a > b ? a : b)
431
432-static SVCXPRT **__svc_xports;
433+SVCXPRT **__svc_xports;
434 int __svc_maxrec;
435
436 /*
437@@ -194,6 +194,21 @@ __xprt_do_unregister (xprt, dolock)
438 rwlock_unlock (&svc_fd_lock);
439 }
440
441+int
442+svc_open_fds()
443+{
444+ int ix;
445+ int nfds = 0;
446+
447+ rwlock_rdlock (&svc_fd_lock);
448+ for (ix = 0; ix < svc_max_pollfd; ++ix) {
449+ if (svc_pollfd[ix].fd != -1)
450+ nfds++;
451+ }
452+ rwlock_unlock (&svc_fd_lock);
453+ return (nfds);
454+}
455+
456 /*
457 * Add a service program to the callout list.
458 * The dispatch routine will be called when a rpc request for this
459diff --git a/src/svc_vc.c b/src/svc_vc.c
460index f1d9f00..3dc8a75 100644
461--- a/src/svc_vc.c
462+++ b/src/svc_vc.c
463@@ -64,6 +64,8 @@
464
465
466 extern rwlock_t svc_fd_lock;
467+extern SVCXPRT **__svc_xports;
468+extern int svc_open_fds();
469
470 static SVCXPRT *makefd_xprt(int, u_int, u_int);
471 static bool_t rendezvous_request(SVCXPRT *, struct rpc_msg *);
472@@ -82,6 +84,7 @@ static void svc_vc_ops(SVCXPRT *);
473 static bool_t svc_vc_control(SVCXPRT *xprt, const u_int rq, void *in);
474 static bool_t svc_vc_rendezvous_control (SVCXPRT *xprt, const u_int rq,
475 void *in);
476+static int __svc_destroy_idle(int timeout);
477
478 struct cf_rendezvous { /* kept in xprt->xp_p1 for rendezvouser */
479 u_int sendsize;
480@@ -313,13 +316,14 @@ done:
481 return (xprt);
482 }
483
484+
485 /*ARGSUSED*/
486 static bool_t
487 rendezvous_request(xprt, msg)
488 SVCXPRT *xprt;
489 struct rpc_msg *msg;
490 {
491- int sock, flags;
492+ int sock, flags, nfds, cnt;
493 struct cf_rendezvous *r;
494 struct cf_conn *cd;
495 struct sockaddr_storage addr;
496@@ -379,6 +383,16 @@ again:
497
498 gettimeofday(&cd->last_recv_time, NULL);
499
500+ nfds = svc_open_fds();
501+ if (nfds >= (_rpc_dtablesize() / 5) * 4) {
502+ /* destroy idle connections */
503+ cnt = __svc_destroy_idle(15);
504+ if (cnt == 0) {
505+ /* destroy least active */
506+ __svc_destroy_idle(0);
507+ }
508+ }
509+
510 return (FALSE); /* there is never an rpc msg to be processed */
511 }
512
513@@ -820,3 +834,49 @@ __svc_clean_idle(fd_set *fds, int timeout, bool_t cleanblock)
514 {
515 return FALSE;
516 }
517+
518+static int
519+__svc_destroy_idle(int timeout)
520+{
521+ int i, ncleaned = 0;
522+ SVCXPRT *xprt, *least_active;
523+ struct timeval tv, tdiff, tmax;
524+ struct cf_conn *cd;
525+
526+ gettimeofday(&tv, NULL);
527+ tmax.tv_sec = tmax.tv_usec = 0;
528+ least_active = NULL;
529+ rwlock_wrlock(&svc_fd_lock);
530+
531+ for (i = 0; i <= svc_max_pollfd; i++) {
532+ if (svc_pollfd[i].fd == -1)
533+ continue;
534+ xprt = __svc_xports[i];
535+ if (xprt == NULL || xprt->xp_ops == NULL ||
536+ xprt->xp_ops->xp_recv != svc_vc_recv)
537+ continue;
538+ cd = (struct cf_conn *)xprt->xp_p1;
539+ if (!cd->nonblock)
540+ continue;
541+ if (timeout == 0) {
542+ timersub(&tv, &cd->last_recv_time, &tdiff);
543+ if (timercmp(&tdiff, &tmax, >)) {
544+ tmax = tdiff;
545+ least_active = xprt;
546+ }
547+ continue;
548+ }
549+ if (tv.tv_sec - cd->last_recv_time.tv_sec > timeout) {
550+ __xprt_unregister_unlocked(xprt);
551+ __svc_vc_dodestroy(xprt);
552+ ncleaned++;
553+ }
554+ }
555+ if (timeout == 0 && least_active != NULL) {
556+ __xprt_unregister_unlocked(least_active);
557+ __svc_vc_dodestroy(least_active);
558+ ncleaned++;
559+ }
560+ rwlock_unlock(&svc_fd_lock);
561+ return (ncleaned);
562+}
563--
5641.8.3.1
565
diff --git a/meta/recipes-extended/libtirpc/libtirpc_1.3.2.bb b/meta/recipes-extended/libtirpc/libtirpc_1.3.2.bb
index 45b3d2befc..cc87638c0f 100644
--- a/meta/recipes-extended/libtirpc/libtirpc_1.3.2.bb
+++ b/meta/recipes-extended/libtirpc/libtirpc_1.3.2.bb
@@ -9,7 +9,9 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=f835cce8852481e4b2bbbdd23b5e47f3 \
9 9
10PROVIDES = "virtual/librpc" 10PROVIDES = "virtual/librpc"
11 11
12SRC_URI = "${SOURCEFORGE_MIRROR}/${BPN}/${BP}.tar.bz2" 12SRC_URI = "${SOURCEFORGE_MIRROR}/${BPN}/${BP}.tar.bz2 \
13 file://CVE-2021-46828.patch \
14 "
13UPSTREAM_CHECK_URI = "https://sourceforge.net/projects/libtirpc/files/libtirpc/" 15UPSTREAM_CHECK_URI = "https://sourceforge.net/projects/libtirpc/files/libtirpc/"
14UPSTREAM_CHECK_REGEX = "(?P<pver>\d+(\.\d+)+)/" 16UPSTREAM_CHECK_REGEX = "(?P<pver>\d+(\.\d+)+)/"
15SRC_URI[sha256sum] = "e24eb88b8ce7db3b7ca6eb80115dd1284abc5ec32a8deccfed2224fc2532b9fd" 17SRC_URI[sha256sum] = "e24eb88b8ce7db3b7ca6eb80115dd1284abc5ec32a8deccfed2224fc2532b9fd"