qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Chen Gang <chengang@emindsoft.com.cn>
To: Laurent Vivier <laurent@vivier.eu>, riku.voipio@iki.fi
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH v5] linux-user: syscall: ioctls: support DRM_IOCTL_VERSION
Date: Wed, 3 Jun 2020 19:05:18 +0800	[thread overview]
Message-ID: <ce96cb20-80e7-e561-1eee-fcdca38d376f@emindsoft.com.cn> (raw)
In-Reply-To: <02add5c5-e1ad-050e-229e-c5a7d2afdf2b@vivier.eu>

On 2020/6/3 下午5:49, Laurent Vivier wrote:
> Le 03/06/2020 à 03:08, chengang@emindsoft.com.cn a écrit :
>> +#ifdef HAVE_DRM_H
>> +
>> +static void unlock_drm_version(struct drm_version *host_ver)
>> +{
>> +    if (host_ver->name) {
>> +        unlock_user(host_ver->name, 0UL, 0);
> 
> unlock_user() allows to have a NULL host pointer parameter, so you don't
> need to check. But you must provide the target pointer, with the length.
> The same below.
> 

As far as I know, the unlock_user is defined in
include/exec/softmmu-semi.h, which only checks the len before calling
cpu_memory_rw_debug, and only calls free() for the host pointer.

So we have to be sure that the host pointer must be valid. When we pass
0 length to unlock_user, we want it to free host pointer only.

>> +    if (host_ver->desc_len) {
>> +        host_ver->desc = lock_user(VERIFY_WRITE, target_ver->desc,
>> +                                   target_ver->desc_len, 0);
>> +        if (!host_ver->desc) {
>> +            goto err;
>> +        }
>> +    }
>> +
>> +    unlock_user_struct(target_ver, target_addr, 0);
>> +    return 0;
>> +err:
>> +    unlock_drm_version(host_ver);
>> +    unlock_user_struct(target_ver, target_addr, 0);
>> +    return -ENOMEM;
> 
> In fact it should be -TARGET_EFAULT: it has failed because of access rights.
> 

As far as I know, the lock_user is defined in
include/exec/softmmu-semi.h. If the parameter 'copy' is 0 (in our case),
lock_user will only malloc a host pointer and return it.

In our case, I guess the only failure from malloc() is "no memory".

>> +}
>> 
>> +static inline abi_long host_to_target_drmversion(abi_ulong target_addr,
>> +                                                 struct drm_version *host_ver)
>> +{
>> +    struct target_drm_version *target_ver;
>> +
>> +    if (!lock_user_struct(VERIFY_WRITE, target_ver, target_addr, 0)) {
> 
> I think you should not unlock_struct() in target_to_host_drmversion() so
> you don't have to lock it again here.
> 

OK, thanks.

>> +static abi_long do_ioctl_drm(const IOCTLEntry *ie, uint8_t *buf_temp,
>> +                             int fd, int cmd, abi_long arg)
>> +{
>> +    struct drm_version *ver;
>> +    abi_long ret;
>> +
>> +    switch (ie->host_cmd) {
>> +    case DRM_IOCTL_VERSION:
>> +        ver = (struct drm_version *)buf_temp;
> 
> you should lock the structure here (rather than in
> target_to_host_drmversion())...
> 

OK, thanks.

>> +        ret = target_to_host_drmversion(ver, arg);
>> +        if (is_error(ret)) {
>> +            return ret;
>> +        }
>> +        ret = get_errno(safe_ioctl(fd, ie->host_cmd, ver));
>> +        if (is_error(ret)) {
>> +            unlock_drm_version(ver);
>> +            return ret;
>> +        }
>> +        return host_to_target_drmversion(arg, ver);
> 
> and unlock the structure here (rather than in host_to_target_drmversion()).
> 
> You should return "ret" too.
> 

OK, thanks.

>> +    }
>> +    return -TARGET_EFAULT;
> 
> Why -TARGET_EFAULT? -TARGET_ENOSYS would be better.
> 

OK, thanks.

Chen Gang.




  reply	other threads:[~2020-06-03 11:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03  1:08 [PATCH v5] linux-user: syscall: ioctls: support DRM_IOCTL_VERSION chengang
2020-06-03  9:49 ` Laurent Vivier
2020-06-03 11:05   ` Chen Gang [this message]
2020-06-03 12:03     ` Laurent Vivier
2020-06-04  1:04       ` Chen Gang

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=ce96cb20-80e7-e561-1eee-fcdca38d376f@emindsoft.com.cn \
    --to=chengang@emindsoft.com.cn \
    --cc=laurent@vivier.eu \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).