Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1013027imm; Fri, 15 Jun 2018 09:45:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJuQMc76TQA6SVpX6JH2WIjic4rab7PtiDEfnTsbcnNmpbXDxdPs+Y49DTLuW5f5qeFwjlR X-Received: by 2002:a17:902:3303:: with SMTP id a3-v6mr2893826plc.209.1529081145038; Fri, 15 Jun 2018 09:45:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529081145; cv=none; d=google.com; s=arc-20160816; b=qbbqZC5hNGD2LBCTOxs4F09WWdPRCUJxfYWJHH3ZvDGfX04w447lUACioxQ9UevGbr DoG0M7Cxdosrh4MLT0Xhf2B93UqTm7vQrBtMDinUz7m/plwjMkURG9cKKZXvNfkMUFQw Q7sOrjqaYiZQEW80dyFhXQ8AD1dzHicaExm9gHhAZUlucS25GP3s532l1WlfNtH9pdrx 2dh9ZP21IwPDp0TqO2yUGWEuqWoEf+hmhiyfxYqVA1dCV/zqIfUSGHgrN1Wrxzw7/9Fp oxVnqXnscCGJ1vfVS9AKxvWhNwJD4MEHrEa9sN+ZARt9qu6q1awzEHwjrKlAA8UjBiq+ 0DOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=MEFaJhiXyNan8nBVc3ywGNwatyQN9rFssV/TKLDuqis=; b=fJj7JVr8IntjwJR/NZXN29ojAEc4x5795UmhMw5cHadVDLj771r69YVsXpEB5dfp6w u+vFPXtvp7EbGXcbEOPCCWnx2QK8VMfIYHRV34dto5wvO7aH4XuU+AlEo+Y5DcMb3AQx 3AOGFkz9OgABBjl9ZlsdtoeNSky10JWSNgyB3yisfiuJZjyFeJ00czZ/8F3lZo7jUx5A WSuFmLEHFl8PEHTBpiYrTDcckLbccX7OK6ipMzSKJ+bXlOP1pSC3rJoRMDFcM+08riLA 2OUy4BxYHHOYfvRHYs+9QGHyvO2oMw+mXWgmc99pE5QPryNYQg0GHm/PS0kL+EVW1hWp o6Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="SN2d/mxJ"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y36-v6si2940255pga.89.2018.06.15.09.45.30; Fri, 15 Jun 2018 09:45:45 -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=@google.com header.s=20161025 header.b="SN2d/mxJ"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966068AbeFOQpF (ORCPT + 99 others); Fri, 15 Jun 2018 12:45:05 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:38891 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964992AbeFOQpD (ORCPT ); Fri, 15 Jun 2018 12:45:03 -0400 Received: by mail-oi0-f66.google.com with SMTP id d5-v6so9356721oib.5 for ; Fri, 15 Jun 2018 09:45:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MEFaJhiXyNan8nBVc3ywGNwatyQN9rFssV/TKLDuqis=; b=SN2d/mxJ2goYBb70AhMmblYACvAkaFLsSlBc2ZhM5cyb+JhB9gJAwQV8Kz8NOdUlrI o1degSL5cPf5wJOETaOEV2bCVBfIyEqiSxGjclXdfxDsaOsgdPy2Ae4MupYWRyoPJqJ7 uFAmzybxDYx4ODqQxNLO0QlWmhhaTdx+bwtlqaZl1iD5MJjO7Y0W3szVk8s0nNsyClFR BH2Ipu0pzuLlwy9W+jF/Sn1YehLQ6kp6Pwo+rnO9+nX2Fbqae7VuPLm6iIBQfHq6YMvO zkx6FWcl+sAlJaTeRshwrgsjsrVQcYVHvYEjXbVIIV5HKSPQ9wDc/Uu8unw7Bi9ArpKj pURg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MEFaJhiXyNan8nBVc3ywGNwatyQN9rFssV/TKLDuqis=; b=EJv8r2WiMpHLnKJZCkOuHyXiDRJIIGsWZ5V96PgLiD58gtDRlain2LNdjnrqE+DUXm IcXam2WQgCwMNFvn66HHejPS3T8LQNvd64PunJXhoIm/JSzOFN9+Cvim9+oZSiDcp6sv 9d1O8/XVLYfo7aiF06O17lg+q/yYpAOz+LvGsKpDZR7XFr700F97rO9Y0qbR8oteDHBH k6P9XgYCqJt04ihpnUjnF0WAp3cGFbek3yQZBHZ18Y7Ud35fzKX9qXaRh1nTboGTDypf 3NzPOun/tNzbAjRW80mqA/IXkY7BZyuq/kKuePriZ6WTCh9hgTn7CvnxCqioMVQ7OPe8 hjaw== X-Gm-Message-State: APt69E0plGWWF/1x0YR/irdQW3IHgcZ3x3Lz91RqmI+ShVqGyWqquTuD gh4Bzco7JEA2FzjDBdVunBDcWPCiUcT+eVpjAh0YoA== X-Received: by 2002:aca:6b03:: with SMTP id g3-v6mr1211431oic.219.1529081102715; Fri, 15 Jun 2018 09:45:02 -0700 (PDT) MIME-Version: 1.0 References: <20180615152335.208202-1-jannh@google.com> <20180615164009.GD30522@ZenIV.linux.org.uk> In-Reply-To: <20180615164009.GD30522@ZenIV.linux.org.uk> From: Jann Horn Date: Fri, 15 Jun 2018 18:44:51 +0200 Message-ID: Subject: Re: [PATCH] sg, bsg: mitigate read/write abuse, block uaccess in release To: Al Viro Cc: axboe@kernel.dk, fujita.tomonori@lab.ntt.co.jp, dgilbert@interlog.com, jejb@linux.vnet.ibm.com, martin.petersen@oracle.com, linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, kernel list , Kernel Hardening , security@kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 15, 2018 at 6:40 PM Al Viro wrote: > > On Fri, Jun 15, 2018 at 05:23:35PM +0200, Jann Horn wrote: > > > I've mostly copypasted ib_safe_file_access() over as > > scsi_safe_file_access() because I couldn't find a good common header - > > please tell me if you know a better way. > > The duplicate pr_err_once() calls are so that each of them fires once; > > otherwise, this would probably have to be a macro. > > > > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") > > Cc: > > Signed-off-by: Jann Horn > > --- > > WTF do you mean, in ->release()? That makes no sense whatsoever - > what kind of copy_{to,from}_user() would be possible in there? bsg_release -> bsg_put_device -> bsg_complete_all_commands -> blk_complete_sgv4_hdr_rq -> bsg_scsi_complete_rq -> copy_to_user. I don't think that was intentional. Basically, the sense buffer is copied to a userspace address supplied in the previous ->write() when you ->read() the reply. But when you ->release() the file without reading the reply, they have to clean it up, and for that, they reuse the same code they use for ->read() - so the sense buffer is written to userspace on ->release().