[PATCH v4 4/5] drm: Add decoding of i915 ioctls

Dmitry V. Levin ldv at altlinux.org
Wed Sep 9 11:52:18 UTC 2015


On Tue, Sep 08, 2015 at 04:30:52AM +0300, Dmitry V. Levin wrote:
> On Tue, Sep 08, 2015 at 04:18:11AM +0300, Dmitry V. Levin wrote:
> [...]
> > So the whole function should look smth like this:
> > 
> > static int i915_getparam(struct tcb *tcp, const unsigned int code, long arg)
> > {
> > 	struct drm_i915_getparam param;
> > 
> > 	if (entering(tcp)) {
> > 		if (umove_or_printaddr(tcp, arg, &param))
> > 			return RVAL_DECODED | 1;
> > 		tprints(", {param=");
> 
> or rather
> 		tprints(", ");
> 		if (umove_or_printaddr(tcp, arg, &param))
> 			return RVAL_DECODED | 1;
> 		tprints("{param=");

or rather

static int
i915_getparam(struct tcb *tcp, const unsigned int code, const long arg)
{
	struct drm_i915_getparam param;
	int value;

	if (entering(tcp)) {
		tprints(", ");
		if (umove_or_printaddr(tcp, arg, &param))
			return RVAL_DECODED | 1;
		tprints("{param=");
		printxval(drm_i915_getparams, param.param, "I915_PARAM_???");
		return 0;
	}

	if (!umove(tcp, arg, &param)) {
		tprints(", value=");
		if (!umove_or_printaddr(tcp, (long) param.value, &value)) {
			switch (param.param) {
			case I915_PARAM_CHIPSET_ID:
				tprintf("[%#04x]", value);
				break;
			default:
				tprintf("[%d]", value);
			}
		}
	}
	tprints("}");
	return 1;
}

Note that those structure members that are set by the kernel on exiting
syscall shouldn't normally be printed in case of syserror(tcp).

In case of i915_getparam, no extra check is needed because param.value is
an address supplied by userspace and umove_or_printaddr already performs
all necessary checks, but in other IOWR parsers you might want to use
	if (!syserror(tcp) && !umove(tcp, arg, &param)) {
instead.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20150909/b4f4edf3/attachment.bin>


More information about the Strace-devel mailing list