From: Jamie Lokier <jamie@shareable.org>
To: Riku Voipio <riku.voipio@iki.fi>
Cc: qemu-devel@nongnu.org, Arnaud Patard <arnaud.patard@rtp-net.org>
Subject: Re: [Qemu-devel] [PATCH] fix fcntl support in linux-user.
Date: Tue, 21 Apr 2009 15:39:52 +0100 [thread overview]
Message-ID: <20090421143952.GB6375@shareable.org> (raw)
In-Reply-To: <20090421125142.GB15170@kos.to>
Riku Voipio wrote:
> On Tue, Apr 21, 2009 at 10:21:38AM +0200, Arnaud Patard wrote:
> > Ok, done. New patch attached. Please comment :)
>
> thanks, this is already better. just two comments.
>
> > +static char target_to_host_fcntl_cmd[] = {
> > + [ TARGET_F_GETLK ] = F_GETLK,
> > + [ TARGET_F_SETLK ] = F_SETLK,
> > + [ TARGET_F_SETLKW ] = F_SETLKW,
> > + [ TARGET_F_GETLK64 ] = F_GETLK64,
> > + [ TARGET_F_SETLK64 ] = F_SETLK64,
> > + [ TARGET_F_SETLKW64 ] = F_SETLKW64,
> > + [ TARGET_F_SETOWN ] = F_SETOWN,
> > + [ TARGET_F_GETOWN ] = F_GETOWN,
> > + [ TARGET_F_SETSIG ] = F_SETSIG,
> > + [ TARGET_F_GETSIG ] = F_GETSIG,
> > +};
>
> explict size for table and check for not overflowing?
And check for unset entries. The new code doesn't return EINVAL for
unknown commands as it should. (But it calls the host with a zero
command _if_ the target command is smaller than the table... which
results in EINVAL). The old code wasn't perfect, passing junk command
values to the host that it didn't recognise.
Also, are TARGET_F_GETLK64 and TARGET_F_GETLK distinct values on
64-bit hosts - or even exist at all?
> cmd2 is not a very good variable name, for example host_cmd
> would describe it better.
Agree.
> > - switch(arg2){
> > - case TARGET_F_GETLK64:
> > - cmd = F_GETLK64;
> > - break;
> > - case TARGET_F_SETLK64:
> > - cmd = F_SETLK64;
> > - break;
> > - case TARGET_F_SETLKW64:
> > - cmd = F_SETLK64;
> > - break;
> > - default:
> > - cmd = arg2;
> > - break;
> > - }
> > + cmd = target_to_host_fcntl_cmd[arg2];
The new code behaves differently for unknown arg2 values. The old
code passed junk to the host kernel; the new code passes zero if arg2
< the table size, and reads outside the array otherwise. Both are
surely wrong? Simply return EINVAL if arg2 isn't recognised.
I'm inclined to keeping the switch, adding the other cases
(TARGET_F_GETLK etc.), #ifdef around the ..64 ones, and making the
default case return EINVAL explicitly. A table lookup wouldn't save
anything once you've checked its bounds and for the no-entry case.
room.
-- Jamie
next prev parent reply other threads:[~2009-04-21 14:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-19 20:45 [Qemu-devel] [PATCH] fix fcntl support in linux-user Arnaud Patard
2009-04-20 13:22 ` Riku Voipio
2009-04-21 8:21 ` Arnaud Patard
2009-04-21 12:51 ` Riku Voipio
2009-04-21 14:39 ` Jamie Lokier [this message]
2009-04-21 17:58 ` Riku Voipio
2009-04-22 10:04 ` Arnaud Patard
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=20090421143952.GB6375@shareable.org \
--to=jamie@shareable.org \
--cc=arnaud.patard@rtp-net.org \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
/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.