All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 01/11] lib: Add support for guarded buffers
Date: Mon, 19 Aug 2019 11:06:01 +0200	[thread overview]
Message-ID: <877e79wmme.fsf@rpws.prws.suse.cz> (raw)
In-Reply-To: <20190812143941.8119-2-chrubis@suse.cz>

Hi,

Cyril Hrubis <chrubis@suse.cz> writes:

> +
> +/*
> + * Buffer description consist of a pointer to a pointer and buffer type/size
> + * encoded as a different structure members.
> + *
> + * Only one of the size and iov_sizes can be set at a time.
> + */
> +struct tst_buffers {
> +	/*
> +	 * This pointer points to a buffer pointer.
> +	 */
> +	void *ptr;
> +	/*
> +	 * Buffer size.
> +	 */
> +	size_t size;
> +	/*
> +	 * Array of iov buffer sizes terminated by -1.
> +	 */
> +	int *iov_sizes;
> +};
> +
> +/*
> + * Allocates buffers based on the tst_buffers structure.
> + *
> + * @bufs NULL terminated array of test buffer descriptions.
> + *
> + * This is called from the test library if the tst_test->bufs pointer is set.
> + */
> +void tst_buffers_alloc(struct tst_buffers bufs[]);
> +
> +/*
> + * strdup() that callls tst_alloc().
> + */
> +char *tst_strdup(const char *str);
> +
> +/*
> + * Allocates size bytes, returns pointer to the allocated buffer.
> + */
> +void *tst_alloc(size_t size);
> +
> +/*
> + * Allocates iovec structure including the buffers.
> + *
> + * @sizes -1 terminated array of buffer sizes.
> + */
> +struct iovec *tst_iovec_alloc(int sizes[]);
> +
> +/*
> + * Frees all allocated buffers.
> + *
> + * This is called at the end of the test automatically.
> + */
> +void tst_free_all(void);

We could add guarded buffers to huge numbers of tests by wrapping the
user supplied buffer in various calls to SAFE_* macros and tst_*
functions. This could be configurable at compile time and it should be
detectable if a buffer is already guarded, so double wrapping should not
be an issue.

However I am not sure the current API makes this easy. We should
probably have a tst_free(void *buf) and/or tst_buffer_alloc(struct
tst_buffer *buf) and tst_buffer_free(struct tst_buffer *buf) (which
could just put the buffer on a free list for reuse).

I am not sure if this is something which needs to be addressed now or
can be left for another patch set. My main concern is that one of the
existing API functions will need to be changed.

--
Thank you,
Richard.

  reply	other threads:[~2019-08-19  9:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-12 14:39 [LTP] [PATCH v2 00/11] Introduce guarded buffers Cyril Hrubis
2019-08-12 14:39 ` [LTP] [PATCH v2 01/11] lib: Add support for " Cyril Hrubis
2019-08-19  9:06   ` Richard Palethorpe [this message]
2019-08-19 12:42     ` Cyril Hrubis
2019-08-20  8:25       ` Richard Palethorpe
2019-08-21  9:11         ` Cyril Hrubis
2019-08-12 14:39 ` [LTP] [PATCH v2 02/11] lib: Add a canary " Cyril Hrubis
2019-08-12 14:39 ` [LTP] [PATCH v2 03/11] doc: Add guarded buffers documentation Cyril Hrubis
2019-08-19  9:44   ` Richard Palethorpe
2019-08-12 14:39 ` [LTP] [PATCH v2 04/11] syscalls/accept02: Make use of guarded buffers Cyril Hrubis
2019-08-12 14:39 ` [LTP] [PATCH v2 05/11] syscalls/preadv01: " Cyril Hrubis
2019-08-12 14:39 ` [LTP] [PATCH v2 06/11] syscalls/accept4_01: " Cyril Hrubis
2019-08-12 14:39 ` [LTP] [PATCH v2 07/11] syscalls/add_key04: " Cyril Hrubis
2019-08-12 14:39 ` [LTP] [PATCH v2 08/11] syscalls/adjtimex: " Cyril Hrubis
2019-08-12 14:39 ` [LTP] [PATCH v2 09/11] syscalls/clock_getres01: " Cyril Hrubis
2019-08-12 14:39 ` [LTP] [PATCH v2 10/11] syscalls/clock_settime01: " Cyril Hrubis
2019-08-12 14:39 ` [LTP] [PATCH v2 11/11] syscalls/sendmmsg01: " Cyril Hrubis
2019-08-13  9:53 ` [LTP] [PATCH v2 00/11] Introduce " Li Wang
2019-08-13 10:29   ` Cyril Hrubis
2019-08-20 11:23   ` Cyril Hrubis
2019-08-20 11:55     ` Li Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877e79wmme.fsf@rpws.prws.suse.cz \
    --to=rpalethorpe@suse.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.