Skip to content

Commit e3d43eb

Browse files
committed
xen: introduce xenbus_read_unsigned()
jira VULN-1439 cve-prereq CVE-2022-33741 commit-author Juergen Gross <[email protected]> commit 9c53a17 There are multiple instances of code reading an optional unsigned parameter from Xenstore via xenbus_scanf(). Instead of repeating the same code over and over add a service function doing the job. Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: David Vrabel <[email protected]> (cherry picked from commit 9c53a17) Signed-off-by: Brett Mastbergen <[email protected]>
1 parent 7d898df commit e3d43eb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

drivers/xen/xenbus/xenbus_xs.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,21 @@ int xenbus_scanf(struct xenbus_transaction t,
526526
}
527527
EXPORT_SYMBOL_GPL(xenbus_scanf);
528528

529+
/* Read an (optional) unsigned value. */
530+
unsigned int xenbus_read_unsigned(const char *dir, const char *node,
531+
unsigned int default_val)
532+
{
533+
unsigned int val;
534+
int ret;
535+
536+
ret = xenbus_scanf(XBT_NIL, dir, node, "%u", &val);
537+
if (ret <= 0)
538+
val = default_val;
539+
540+
return val;
541+
}
542+
EXPORT_SYMBOL_GPL(xenbus_read_unsigned);
543+
529544
/* Single printf and write: returns -errno or 0. */
530545
int xenbus_printf(struct xenbus_transaction t,
531546
const char *dir, const char *node, const char *fmt, ...)

include/xen/xenbus.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ __scanf(4, 5)
144144
int xenbus_scanf(struct xenbus_transaction t,
145145
const char *dir, const char *node, const char *fmt, ...);
146146

147+
/* Read an (optional) unsigned value. */
148+
unsigned int xenbus_read_unsigned(const char *dir, const char *node,
149+
unsigned int default_val);
150+
147151
/* Single printf and write: returns -errno or 0. */
148152
__printf(4, 5)
149153
int xenbus_printf(struct xenbus_transaction t,

0 commit comments

Comments
 (0)