Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2004028imm; Thu, 7 Jun 2018 04:01:24 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIRqj4BZpV2inl3fvbV84M9yPUD+VOS6H8+f9r/ILYrRRBGgU10jAg7Vlgxsw6xm/KR2xgF X-Received: by 2002:a62:9f16:: with SMTP id g22-v6mr1305775pfe.207.1528369284363; Thu, 07 Jun 2018 04:01:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528369284; cv=none; d=google.com; s=arc-20160816; b=rhETUK9NOEedDkmIr5hI1Bjyshshf3Cm3zsSSz9UxnZRTfsI7aZes19OA7PWkvN6q1 1Ic4cn87pakOGl9yRQB6o5iS7xvnm+DmEuW9dYXpIGOCllzrM4Pr0BqrPRAz2pH4t5Cw 1dWUbvxWzrCgtdjZwYoYDw3a3vYyE9i0niJ2UeSYDJfkZYXDMAmLQrnEnBOEM6WaV5i8 Fe0q3EHmXS7+dXMqi1adGP1f5v4pJm0tWF6qyEbOPkDPsniclrAbSTt7gvifPCIMPC3b 3gZrWlQgbFjQ74FHd+dTrtwbzZhDOx4112oTbZR27tM2Zy3yihg7JhV0yLzgysnmtgCE 0r9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=uKVq3W5B9L0JYpUXfqU464r97Ok4aARA6435byXTkao=; b=AamU63G3QnT1xhwwXEebY6ekDmXzQbspvabtViK4sYR0w2usd0uVqXsQWo/rW2c+kM vxxTyDO5Yr0aJMcXSXOSUSC/W0oI2Tf3wllycG2PMPfXXsIRibSJuBP0504iJcHsFq6V UbaFoEgv7qx3cE+S8aJ9FlpJnI5bIY13UAJinvpjMO/4UPKentmLrZ7e5lAy9E2TEHNC kmJB8da6QsWfG/bYwfkeMLk7hPoXq0cSMG4Bbw/65EAWT15FbnMK80IIoyLAnGDrVTnS od05SSo9g19NQzQzA+gIFxbVLBpeWCfwHevxRkdSOLp2NjvZ6fq9os5wEHJx0xYUhnNh l4zg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y20-v6si6591057pfm.186.2018.06.07.04.01.09; Thu, 07 Jun 2018 04:01:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932568AbeFGKV0 (ORCPT + 99 others); Thu, 7 Jun 2018 06:21:26 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:14126 "EHLO SMTP03.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932183AbeFGKVZ (ORCPT ); Thu, 7 Jun 2018 06:21:25 -0400 X-IronPort-AV: E=Sophos;i="5.49,486,1520899200"; d="scan'208";a="56620869" From: Paul Durrant To: , CC: Paul Durrant , Boris Ostrovsky , Juergen Gross , Dan Carpenter Subject: [PATCH] xen/privcmd: fix static checker warning Date: Thu, 7 Jun 2018 11:21:13 +0100 Message-ID: <1528366873-25430-1-git-send-email-paul.durrant@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 3ad0876554ca ("xen/privcmd: add IOCTL_PRIVCMD_MMAP_RESOURCE") introduced a static checker warning: drivers/xen/privcmd.c:827 privcmd_ioctl_mmap_resource() warn: passing casted pointer 'pfns' to 'xen_remap_domain_mfn_array()' 64 vs 32. caused by this cast: 827 num = xen_remap_domain_mfn_array(vma, 828 kdata.addr & PAGE_MASK, 829 pfns, kdata.num, (int *)pfns, ^^^^^^^^^^^ The reason for the cast is that xen_remap_domain_mfn_array() requires an array of ints to store error codes. It is actually safe to re-use the pfns array for this purpose but it does look odd (as well as leading to the warning). It would also be easy for a future implementation change to make this re-use unsafe so this patch modifies privcmd to use a separately allocated array for error codes. Reported-by: Dan Carpenter Signed-off-by: Paul Durrant --- Cc: Boris Ostrovsky Cc: Juergen Gross Cc: Dan Carpenter --- drivers/xen/privcmd.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 8ae0349..8507c13 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -822,11 +822,18 @@ static long privcmd_ioctl_mmap_resource(struct file *file, void __user *udata) unsigned int domid = (xdata.flags & XENMEM_rsrc_acq_caller_owned) ? DOMID_SELF : kdata.dom; + int *errs; int num; + errs = kcalloc(kdata.num, sizeof(*errs), GFP_KERNEL); + if (!errs) { + rc = -ENOMEM; + goto out; + } + num = xen_remap_domain_mfn_array(vma, kdata.addr & PAGE_MASK, - pfns, kdata.num, (int *)pfns, + pfns, kdata.num, errs, vma->vm_page_prot, domid, vma->vm_private_data); @@ -836,12 +843,14 @@ static long privcmd_ioctl_mmap_resource(struct file *file, void __user *udata) unsigned int i; for (i = 0; i < num; i++) { - rc = pfns[i]; + rc = errs[i]; if (rc < 0) break; } } else rc = 0; + + kfree(errs); } out: -- 2.1.4