Files
xen/tools/include/xen-tools/libs.h
T
Juergen Gross 268369d8e3 tools/xenstore: limit max number of nodes accessed in a transaction
Today a guest is free to access as many nodes in a single transaction
as it wants. This can lead to unbounded memory consumption in Xenstore
as there is the need to keep track of all nodes having been accessed
during a transaction.

In oxenstored the number of requests in a transaction is being limited
via a quota maxrequests (default is 1024). As multiple accesses of a
node are not problematic in C Xenstore, limit the number of accessed
nodes.

In order to let read_node() detect a quota error in case too many nodes
are being accessed, check the return value of access_node() and return
NULL in case an error has been seen. Introduce __must_check and add it
to the access_node() prototype.

This is part of XSA-326 / CVE-2022-42314.

Suggested-by: Julien Grall <julien@xen.org>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
2022-11-01 13:05:44 +00:00

71 lines
1.9 KiB
C

#ifndef __XEN_TOOLS_LIBS__
#define __XEN_TOOLS_LIBS__
#ifndef BUILD_BUG_ON
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#define BUILD_BUG_ON(p) ({ _Static_assert(!(p), "!(" #p ")"); })
#else
#define BUILD_BUG_ON(p) ((void)sizeof(char[1 - 2 * !!(p)]))
#endif
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
#endif
#ifndef MAX
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#endif
#ifndef MIN
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#endif
#ifndef min
#define min(x, y) \
({ \
const typeof(x) _x = (x); \
const typeof(y) _y = (y); \
(void) (&_x == &_y); \
(_x < _y) ? _x : _y; \
})
#endif
#ifndef max
#define max(x, y) \
({ \
const typeof(x) _x = (x); \
const typeof(y) _y = (y); \
(void)(&_x == &_y); \
(_x > _y) ? _x : _y; \
})
#endif
#ifndef min_t
#define min_t(type, x, y) \
({ \
const type _x = (x); \
const type _y = (y); \
(_x < _y) ? _x: _y; \
})
#endif
#ifndef max_t
#define max_t(type, x, y) \
({ \
const type _x = (x); \
const type _y = (y); \
(_x > _y) ? _x: _y; \
})
#endif
#ifndef ROUNDUP
#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
#endif
#ifndef __must_check
#define __must_check __attribute__((__warn_unused_result__))
#endif
#endif /* __XEN_TOOLS_LIBS__ */