Received: by 10.192.165.148 with SMTP id m20csp2565577imm; Sun, 6 May 2018 18:43:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrCYrgF0h87X0fqr/5ygOAiDlD19jreg6N7frrxUpW8wlEMJDYV/sWZSW+IOajgLSArUGeJ X-Received: by 2002:a63:921a:: with SMTP id o26-v6mr28893999pgd.438.1525657383682; Sun, 06 May 2018 18:43:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525657383; cv=none; d=google.com; s=arc-20160816; b=hY1zSxuEMEgTJ6p816T7ebWhN09EBjMakzkdX0MxLJuSB2gcPGQfqyU3vCKPhiYmGN Q1eLhKBjkUrnYiT76Pc6ReifYtFaSh5grqqDOwUlOgCoxPwW4LYNeJx2uXTYpAGE1982 5Y4wRnBvqn7znAraXKDPzkCC1EadJ++p0c+tbQ4bvTyHbY9c+xpcQxZ7ucJzm+O2wY99 U1xV6IPtZIJqlydVDvUTQ8Sp6L0bDGXMytPY2Ublqq1553q5b7A7WOPTLbEbPFPrAUmX gwaDUf1JOaKZ8nsmjSbCFLmcKyZuOHtR1zZn/sAT5kCWmdapZt7ds6yQ/dCxETEa3tWq SPew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=J15IWbVrYpfOVfhKOUz9DcdEiMTKc8nxopDlLYQFhm0=; b=d0c9bmKP/3G319KIJdPdlg6Wij0TtiHNfP/uQXC9s+sa67gO9QilPPJJ/oljheD8r+ hoZuNUQYad94fLaVNxgy910Q/nafcOqeyDdIYlFSqyyEPkA8+lwjW8VW7OOIIl6bxCao l70QAofBn9UH09DClnUeUdGbLbmYvbD7PoyP7E0tdFTWA449Jdko3fB5YgTUYOPvKHio O/P8O5l+bvp9ZFdA2kjktAJA8+10NtArEf7H5FVrNQUy3GdF1LMV25Gmsb/3ZkUuV/Id BlxSus19MJEExwUiPYWn/2Gf2uTCLQWsLmuNJAvX5npl6hlpUaPDUtHt0dpKVtBW4X4u HjVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RLZ5bmxI; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i7-v6si7306942pgq.507.2018.05.06.18.42.49; Sun, 06 May 2018 18:43:03 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RLZ5bmxI; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751906AbeEGBmi (ORCPT + 99 others); Sun, 6 May 2018 21:42:38 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:42211 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751444AbeEGBmg (ORCPT ); Sun, 6 May 2018 21:42:36 -0400 Received: by mail-pf0-f194.google.com with SMTP id p14so10161544pfh.9; Sun, 06 May 2018 18:42:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=J15IWbVrYpfOVfhKOUz9DcdEiMTKc8nxopDlLYQFhm0=; b=RLZ5bmxI4U9kEE3CXsjVtP4TtZnC0cDQP82o8pLNBlPU118UwLfhyLvnj843Gfg5/0 wr6lJotIgUeO3lJMoCS36D0tx6QTP80IQetydCMmXEqvo0VR86QOjXLxtK0ciinf1hxL lXybSl66ob4G7QaoBdB/Ykc4B91zy4plyZDfjasSs/3hFlhJpilHZ+YdAirjbHEm48AQ ElcKfTgmJ2VwWGSNdD8dG6m4jWtS6wab3dcbR6reVwNrCJKLQgp8fOkHXXp2RpNBrlF8 qgPE+QunRf5mYrmpxjKY88T08Cqf6xpbOpeYulpirPxHXp7wl7kodmYUdo/Q987/ERFa DBew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=J15IWbVrYpfOVfhKOUz9DcdEiMTKc8nxopDlLYQFhm0=; b=l+NIxkRFqJmjYSodBeoxpH4YEvRHc+Mh6xVymKxFbgyhAwIBdhOuqeBOA0uH+yd6wu sDHx2y3hGax5X5K/S6MB6xxxN5T7WZJ23ZboOqVkoAE9WZwjjJD7ep2j15b+owok1ZBV OvYdxpOSNrVKbQmiFVOfRxiy7GxPdXUnuL8WiwF77LxNB5dGeFbK8W0xpCPZsGYD7Sk2 HDv0c+/oA79IzurjTf7qqzJiK/7ZfuIG7xmGu0SNrjcpcAU/j7f2UR1xRznJhWktAm4F Sw0xcCPzfEgppwMOyNtpbjrPOFXcwn2PLK3QK1vmbc3BSVUztIkUYOa7o1afZ6wNEvcM De5Q== X-Gm-Message-State: ALQs6tA3AMrmVoFFhA8d6yh5zBuIRyOpaxxkkoesR6rgvWIU9ov1t6t4 FLUPidxYN0tNQcjWBPNLLM4= X-Received: by 10.98.247.19 with SMTP id h19mr24982165pfi.165.1525657355978; Sun, 06 May 2018 18:42:35 -0700 (PDT) Received: from debian.debian ([2001:250:582a:5:9a4:c5c6:65c4:674d]) by smtp.gmail.com with ESMTPSA id c8sm38220193pfi.96.2018.05.06.18.42.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 06 May 2018 18:42:35 -0700 (PDT) Date: Mon, 7 May 2018 09:42:31 +0800 From: YU Bo To: Wenwen Wang Cc: Kangjie Lu , Armin Schindler , Karsten Keil , "open list:ISDN SUBSYSTEM" , open list Subject: Re: [PATCH] isdn: eicon: fix a missing-check bug Message-ID: <20180507014230.5wquwxjoeztuv2k5@debian.debian> Mail-Followup-To: Wenwen Wang , Kangjie Lu , Armin Schindler , Karsten Keil , "open list:ISDN SUBSYSTEM" , open list References: <1525548766-13017-1-git-send-email-wang6495@umn.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline In-Reply-To: <1525548766-13017-1-git-send-email-wang6495@umn.edu> User-Agent: NeoMutt/20180323-232-a7e428-dirty Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, I am just notice your subject line.There are missing something i think On Sat, May 05, 2018 at 02:32:46PM -0500, Wenwen Wang wrote: >In divasmain.c, the function divas_write() firstly invokes the function >diva_xdi_open_adapter() to open the adapter that matches with the adapter >number provided by the user, and then invokes the function diva_xdi_write() >to perform the write operation using the matched adapter. The two functions >diva_xdi_open_adapter() and diva_xdi_write() are located in diva.c. > >In diva_xdi_open_adapter(), the user command is copied to the object 'msg' >from the userspace pointer 'src' through the function pointer 'cp_fn', >which eventually calls copy_from_user() to do the copy. Then, the adapter >number 'msg.adapter' is used to find out a matched adapter from the >'adapter_queue'. A matched adapter will be returned if it is found. >Otherwise, NULL is returned to indicate the failure of the verification on >the adapter number. > >As mentioned above, if a matched adapter is returned, the function >diva_xdi_write() is invoked to perform the write operation. In this >function, the user command is copied once again from the userspace pointer >'src', which is the same as the 'src' pointer in diva_xdi_open_adapter() as >both of them are from the 'buf' pointer in divas_write(). Similarly, the >copy is achieved through the function pointer 'cp_fn', which finally calls >copy_from_user(). After the successful copy, the corresponding command >processing handler of the matched adapter is invoked to perform the write >operation. > >It is obvious that there are two copies here from userspace, one is in >diva_xdi_open_adapter(), and one is in diva_xdi_write(). Plus, both of >these two copies share the same source userspace pointer, i.e., the 'buf' >pointer in divas_write(). Given that a malicious userspace process can race >to change the content pointed by the 'buf' pointer, this can pose potential >security issues. For example, in the first copy, the user provides a valid >adapter number to pass the verification process and a valid adapter can be >found. Then the user can modify the adapter number to an invalid number. >This way, the user can bypass the verification process of the adapter >number and inject inconsistent data. > >To avoid such issues, this patch adds a check after the second copy in the >function diva_xdi_write(). If the adapter number is not equal to the one >obtained in the first copy, (-4) will be returned to divas_write(), which >will then return an error code -EINVAL. > >Signed-off-by: Wenwen Wang >--- > drivers/isdn/hardware/eicon/diva.c | 6 +++++- > drivers/isdn/hardware/eicon/divasmain.c | 3 +++ > 2 files changed, 8 insertions(+), 1 deletion(-) > >diff --git a/drivers/isdn/hardware/eicon/diva.c b/drivers/isdn/hardware/eicon/diva.c >index 944a7f3..46cbf76 100644 >--- a/drivers/isdn/hardware/eicon/diva.c >+++ b/drivers/isdn/hardware/eicon/diva.c >@@ -440,6 +440,7 @@ diva_xdi_write(void *adapter, void *os_handle, const void __user *src, > int length, divas_xdi_copy_from_user_fn_t cp_fn) > { > diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) adapter; >+ diva_xdi_um_cfg_cmd_t *p; > void *data; > > if (a->xdi_mbox.status & DIVA_XDI_MBOX_BUSY) { >@@ -461,7 +462,10 @@ diva_xdi_write(void *adapter, void *os_handle, const void __user *src, > > length = (*cp_fn) (os_handle, data, src, length); > if (length > 0) { >- if ((*(a->interface.cmd_proc)) >+ p = (diva_xdi_um_cfg_cmd_t *) data; >+ if (a->controller != (int)p->adapter) { >+ length = -4; >+ } else if ((*(a->interface.cmd_proc)) > (a, (diva_xdi_um_cfg_cmd_t *) data, length)) { > length = -3; > } >diff --git a/drivers/isdn/hardware/eicon/divasmain.c b/drivers/isdn/hardware/eicon/divasmain.c >index b9980e8..a03c658 100644 >--- a/drivers/isdn/hardware/eicon/divasmain.c >+++ b/drivers/isdn/hardware/eicon/divasmain.c >@@ -614,6 +614,9 @@ static ssize_t divas_write(struct file *file, const char __user *buf, > case -3: > ret = -ENXIO; > break; >+ case -4: >+ ret = -EINVAL; >+ break; > } > DBG_TRC(("write: ret %d", ret)); > return (ret); >-- >2.7.4 >