Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7758128ybi; Thu, 6 Jun 2019 00:45:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqyrNg9jAoPXLq0qM6nVepr6cxBOuNCVNulIrJB6cA0c0PF/3TSamLk7PPrvedrTm1wLHCxL X-Received: by 2002:a62:582:: with SMTP id 124mr52359191pff.209.1559807115460; Thu, 06 Jun 2019 00:45:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559807115; cv=none; d=google.com; s=arc-20160816; b=ZOKO77MZy+YpY+eVwQWfwCGrsTEegYHrpIVkkZxaV1xaYnE8VwaeWxn+TSaKfwaP2u TwJ1JpKoAgLl+FSU3s9p6mmr3Or0gpKkHam8aL6hZ4Du0osz+cFmV/iZfSwSAM7rwC3x OuzBNDWND9gMmx+0v0ox4wF+THueoJyOGaZpEMV7gzhFAh04oNf6f/Vk6MWwh8bsOFCi wi97uRskXfz5Tm4ooZUeih6u5oea9DIFeeGtPRQpTq9P9T5J6gNzMq3Tl77mgTcWaSZE 9QErdf5PfmRebFnh5XWrooX4+OGiXf+ERyMWdX+TFKNutv5aDmZvG5ObUtWU8SWCukQG HwVQ== 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:message-id:subject:cc :to:from:date:dkim-signature; bh=hMKmVMGvuYghM2RFGeSJw2TVBQZRwZNWp/oZeq+70J8=; b=1FKLIbxHQvuQ45VwnUQ+cP/7yzSJmm83Lh36pRRD7RW0HJlrvkzmB3iM83nqLfHB4Y PE7g9nEfEQFd6BwksQV70Jm7CsML4op/+KBJ48o+MKhtS+f0iacU1JAHXtDFQjwDuqZY soHwwLcTxUnMC5aKC//BLmFTZDgUJmUkWP1QCOsCv+tvjCzndPlL3VPkmuQSANUEvLPK gN2qSjzHNomHDke22gRWT3Wc2Bdn4u8ez+VEVztMgwQ/wuPyP5lJFc3sIW+D0CvZ84RB C77UyeMZDiu15LGjF9du2WsR+VDZyyQlEDT8UBv69e5vSHzDwo9Nk4zAas1t5WKRFF1o 8gSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="ZEVBYQ/j"; 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 c3si1351122pgi.358.2019.06.06.00.44.59; Thu, 06 Jun 2019 00:45:15 -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="ZEVBYQ/j"; 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 S1726800AbfFFHnn (ORCPT + 99 others); Thu, 6 Jun 2019 03:43:43 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:46421 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725267AbfFFHnn (ORCPT ); Thu, 6 Jun 2019 03:43:43 -0400 Received: by mail-wr1-f66.google.com with SMTP id n4so1246680wrw.13; Thu, 06 Jun 2019 00:43:41 -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:references:mime-version :content-disposition:in-reply-to:user-agent; bh=hMKmVMGvuYghM2RFGeSJw2TVBQZRwZNWp/oZeq+70J8=; b=ZEVBYQ/jzqpS6ukiE7bRSgDO82tLgsQV02m3WFjdt/MLOQEmp+qt1SFqiuW+RaTHTt nzh3W01MCjlfAHeEDBmmB0/vQU5Z/9Ce+L32CgRBMijRobxpmX2/8VG/cT1NY8FWklUf dplk6FE5NMxLAHF7aJoZ5LC15XN+4kCNBluSM11tIp4t9a90dg0IEx0b9rrqppfFS9X1 6Kk2E9Oi9OcYEldLyRxAVKb6DyKEgZBuhMIE8Qn4duffT0Epedy/vjw+FWCirRsm7Viq B505bt/FV5fCT6jyKRm3q3IfK5MOAJVBkFdGmKpgDOowZ1DYXUOnwLYBIaeITcToAefk dlag== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=hMKmVMGvuYghM2RFGeSJw2TVBQZRwZNWp/oZeq+70J8=; b=PJ65+6lHvVkAaHPEMwm2Zqo/HfViEcYK/ay/AeOuVTz5KUKg3gOiNUmADe1Nya5ROB hXAmlYpqAS5vmGQjZJLiyXTpMYer/pM/d8zAwJPgOPeTnlr/DVDa8T5jIMzUUMxDg58+ eAMF3h5xcZh4ufTkd4P+vcr07rMxl48ZYVW7fZOiRZrvq2yizJWNbsulYQln43s+ngRV CBrRxUG7998yDbvoobH36K/wNlPhfjhoMloX+9qKCEkx8LvTfVjWXb60x9MaKnICOsPz C4OfazO9Q+FKuPz9jLsaqr6x09ASRh/lKanK9FF4viYFyloNak3EeD1PILGpfQS1ExKw xrFw== X-Gm-Message-State: APjAAAUE5v1w/+JZGbXoG79nsrSII8DIMqJ2eiknlnIxFh5qTHY2u9PS 0G1Tq3UQBrxeToJx/LBtJesSYmcl X-Received: by 2002:adf:ce03:: with SMTP id p3mr30759497wrn.94.1559807021232; Thu, 06 Jun 2019 00:43:41 -0700 (PDT) Received: from zhanggen-UX430UQ ([108.61.173.19]) by smtp.gmail.com with ESMTPSA id t140sm1002151wmt.0.2019.06.06.00.43.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jun 2019 00:43:40 -0700 (PDT) Date: Thu, 6 Jun 2019 15:43:33 +0800 From: Gen Zhang To: Jiri Slaby Cc: dgilbert@interlog.com, jejb@linux.ibm.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] sg: fix a double-fetch bug in sg_write() Message-ID: <20190606074333.GA7078@zhanggen-UX430UQ> References: <20190531012704.GA4541@zhanggen-UX430UQ> <38bbd54f-d85b-e529-36ad-5c1809bb435f@suse.cz> <20190605153532.GA4051@zhanggen-UX430UQ> <2d322852-4861-929a-28ed-c4b41bea5ba6@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2d322852-4861-929a-28ed-c4b41bea5ba6@suse.cz> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 06, 2019 at 07:01:26AM +0200, Jiri Slaby wrote: > On 05. 06. 19, 17:35, Gen Zhang wrote: > > On Wed, Jun 05, 2019 at 08:41:11AM +0200, Jiri Slaby wrote: > >> On 31. 05. 19, 3:27, Gen Zhang wrote: > >>> In sg_write(), the opcode of the command is fetched the first time from > >>> the userspace by __get_user(). Then the whole command, the opcode > >>> included, is fetched again from userspace by __copy_from_user(). > >>> However, a malicious user can change the opcode between the two fetches. > >>> This can cause inconsistent data and potential errors as cmnd is used in > >>> the following codes. > >>> > >>> Thus we should check opcode between the two fetches to prevent this. > >>> > >>> Signed-off-by: Gen Zhang > >>> --- > >>> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c > >>> index d3f1531..a2971b8 100644 > >>> --- a/drivers/scsi/sg.c > >>> +++ b/drivers/scsi/sg.c > >>> @@ -694,6 +694,8 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos) > >>> hp->flags = input_size; /* structure abuse ... */ > >>> hp->pack_id = old_hdr.pack_id; > >>> hp->usr_ptr = NULL; > >>> + if (opcode != cmnd[0]) > >>> + return -EINVAL; > >>> if (__copy_from_user(cmnd, buf, cmd_size)) > >>> return -EFAULT; > >> > >> You are sending the same patches like a broken machine. Please STOP this > >> and give people some time to actually review your patches! (Don't expect > >> replies in days.) > >> > > Thanks for your reply. I resubmitted this one after 8-day-no-reply. I > > don't judge whether this is a short time period or not. I politely hope > > that you can reply more kindly. > > There is no reason to be offended. I am just asking you to wait a bit > more before reposting. 8 days is too few. My personal experience says to > give patches like these something close to a month, esp. during the > merge window. The issues are present for a long time, nobody hit them > during that timeframe, so there is no reason to haste. Thanks for your reply, and I will keep this in mind. > > > I am just a PhD candidate. All I did is submitting patches, discussing > > with maintainers in accordance with linux community rules for academic papers. > > Yes, despite I have no idea what "linux community rules for academic > papers" are. I mean, these patches come from a research project prototype. Submitting patches, and getting it applied can be demonstrated in the experiment part of research paper. Thanks Gen > > > I guess that you might be busy person and hope that submitting patches > > didn't bother you. > > It does not bother me at all. Patches are welcome, but newcomers tend to > send new versions of patches (or reposts) too quickly. It then leads to > wasting time of people where one person comments on one version and the > others don't see it and reply to some other. > > thanks, > -- > js > suse labs