usdt_parser: fix parser pipe I/O error handling
PATCH 3/6 usdt_parser: fix parser pipe I/O error handling
Use ssize_t for read() and write() return values, return negative errno from usdt_parser_write_one() to match its callers, and cap the reply size advertised by the jailed parser before allocating host memory.
Signed-off-by Kris Van Hees <[email protected]>
--- dtprobed/dtprobed.c | 8 +++- libcommon/usdt_parser.c | 2 +- libcommon/usdt_parser.h | 13 +++++- libcommon/usdt_parser_host.c | 84 +++++++++++++++++++++++++++++++++--- 4 files changed, 95 insertions(+), 12 deletions(-)
dtprobed/dtprobed.c +6 -2
@@ -935,10 +935,14 @@ process_dof(pid_t pid, int out, int in, dev_t dev, ino_t inum, dev_t exec_dev,dt_list_t accum = {0 }; do { + int parser_err; + errmsg = "DOF parser write failed"; - while ((errno = usdt_parser_host_write(out, dh, data)) == EAGAIN); - if (errno != 0) + while ((parser_err = usdt_parser_host_write(out, dh, data)) == -EAGAIN); + if (parser_err != 0) { + errno = parser_err < 0 ? -parser_err : parser_err; goto err; + } /* * Wait for parsed reply. If it fails, try once more; possibly
libcommon/usdt_parser.c +1 -1
@@ -71,7 +71,7 @@ usdt_copyin(int in, char *buf_, size_t sz)memset (buf,0 , sz);for (i =0 ; i < sz; ) { -size_t ret; +ssize_t ret; ret =read (in, buf + i, sz - i);
libcommon/usdt_parser.h +11 -2
@@ -178,6 +178,15 @@ typedef struct dof_parsed {#define DIT_ARGS_NATIVE_HEADSZ offsetof(dof_parsed_t, nargs.args)#define DIT_ARGS_XLAT_HEADSZ offsetof(dof_parsed_t, xargs.args)#define DIT_ARGS_MAP_HEADSZ offsetof(dof_parsed_t, argmap.argmap) +#define DIT_BASE_HEADSZ offsetof(dof_parsed_t, provider) +#define DIT_EOF_HEADSZ DIT_BASE_HEADSZ + +/* +* This is the maximum message size for dof_parsed_t (header + extra data). +* Parser replies are derived from one parser input block, which is already +* capped at DOF_MAXSZ. +*/ +#define DIT_MAX_SIZE DOF_MAXSZ/* * Host-side: in usdt_parser_host.c.
@@ -187,7 +196,7 @@ typedef struct dof_parsed {/* * Write the USDT definitions data to the parser pipe OUT. * -* Returns 0 on success or a positive errno value on error. +* Returns 0 on success or a negative errno value on error. */ int usdt_parser_host_write (int out,const dof_helper_t *dh,const usdt_data_t *data);
@@ -250,7 +259,7 @@ int usdt_parse_notes(int out, dof_helper_t *dhp, usdt_data_t *data);/* * Write something to the parser pipe OUT. * -* Returns 0 on success or a positive errno value on error. +* Returns 0 on success or a negative errno value on error. */ int usdt_parser_write_one (int out,const void *buf,size_t size);
libcommon/usdt_parser_host.c +77 -7
135 lines not on this page · raw message
Signature · 1 line
2.47.3