Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp257491pxb; Wed, 27 Oct 2021 02:27:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQFa00uD0r4ykD6smrvuuu8vd8EGAywzbSSR+FdgVJWcvki1FSCSbKwJ/15aklerK8/moA X-Received: by 2002:a17:90b:2247:: with SMTP id hk7mr4483805pjb.159.1635326825635; Wed, 27 Oct 2021 02:27:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635326825; cv=none; d=google.com; s=arc-20160816; b=Rz6RGv8zwttbYQ05TXCVK+IZrzxp2Kf06Wr9DgHU2hJpXiYpKm803IdXK7ZsmpwB76 MuBD6s99s+nYbZg+Nr23n3ht8f4f/PxS0PEv/dySrXpOjq6vwMgH1aCOc4SU1ht37XYs dyCy6+yUJVtW85AnDmDuKHvEoqz02j06rqWAULhW236KK5v8s3Hmc5GneGY1dE9wb8cH 6XULwVKdKtNs4PsBBgkZ2C5mWbPDO90yM+7gTc4GKl5uvYJgVUEeZH0pweOHgxNDew81 UIdf/3VSP4zpQnYu5uWKc2rAaqUCSjB7ql/gxsPvk3r2rvb04F9o2qkO9KOftzJCWYlk yWdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=VZmINpwcYY7kcvI7sKLaSgNG7WCxmd5BZ4iNpf7lS1s=; b=zA29ZXjKxE8kMePDfBUDhowBRIQxrA+kQ0NmLEs4qMuiMu7ec8GggnrumL5QXD1njv lVuhNHoJD2UnwwIAD0Ia70CBV7+DXAxPw71cHZ8ttynsnSx1q0Hnj/8VTjzxV/B5l/mq 8lnUGm4QShLq4SeHJV+CtKfVzzZhzVoqfbMV/EcykV+lg2c438nY9uJ4jD1AJwMhGBh4 y6BDZ208JH9auwsNRVKFw5Bi9uPc+Z6L+MnlseE9idQYwySIakTt5ditJkdcSVXQTe2Y wQddHf5c+DfZrsTDyCfNI2Ln9CnouQgIuG3qPXX9Lm69G2VRBTUxfjKipTdWOXcdrJtk b2GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=OsqaCKMu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z12si373537pgu.293.2021.10.27.02.26.50; Wed, 27 Oct 2021 02:27:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=OsqaCKMu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235898AbhJZT1O (ORCPT + 99 others); Tue, 26 Oct 2021 15:27:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231424AbhJZT1M (ORCPT ); Tue, 26 Oct 2021 15:27:12 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53BC9C061570 for ; Tue, 26 Oct 2021 12:24:48 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id u21so996124lff.8 for ; Tue, 26 Oct 2021 12:24:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VZmINpwcYY7kcvI7sKLaSgNG7WCxmd5BZ4iNpf7lS1s=; b=OsqaCKMuKFeRuWXmhZzecH1PFurN3y1S2AB1+cEKAaxcheLMIwVa1+mU9xaI+48tSD hDW/GsZ40FpWHVKK/6DfQVSTBtioB3fbYc70ILsRQJsX9ufj7I2BdNObVy9O6WfiMW1v DiUsn9LYY/9cPMqSPRQHNfkJU6lnB2qdNQ6Us= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VZmINpwcYY7kcvI7sKLaSgNG7WCxmd5BZ4iNpf7lS1s=; b=GtZC9TPYr/gj3TTNA8l6ym+BvVwW2lu+4HZ5sSnlGuCnXD6J/yjv9uZGL4pQuTIWJU 06eBZayyaSwpVdvcrHnOZBkJoZREXWRDr8Dqztv5qQRcQHs9p8fshHjOqESuHJZ0zZd+ 6NYbf/7hGGuw9ZNTXrkSz0OHHHFhPOqJ7fhnR6jiXvRljjZ/HSZDdy+mGPfiM6iJWR62 xMayrHybGwGoi2Ua/1O0ZzIDnPWjYBSX3YHJXQtlkKZmIrNeizhhEauNKrc+OkNW0c0x MJGN8DBXy7ePvAHQWKw/GtalYfmEvc8fOF3WfMzhlxl1PABWFeqeTXMyPIB3simrjP22 bUvw== X-Gm-Message-State: AOAM53015tWFJLLWwgeer8mO1C8G9iI6hjXNUS2UBDQU0ziDo0y3iHsX OcvE37rXjRArmpw9hroTKjsfQ083df+1erwS X-Received: by 2002:a05:6512:2111:: with SMTP id q17mr5250759lfr.338.1635276286250; Tue, 26 Oct 2021 12:24:46 -0700 (PDT) Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com. [209.85.208.180]) by smtp.gmail.com with ESMTPSA id n16sm428342ljc.137.2021.10.26.12.24.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 Oct 2021 12:24:46 -0700 (PDT) Received: by mail-lj1-f180.google.com with SMTP id k13so559725ljj.12 for ; Tue, 26 Oct 2021 12:24:46 -0700 (PDT) X-Received: by 2002:a2e:bc24:: with SMTP id b36mr28005819ljf.95.1635275910507; Tue, 26 Oct 2021 12:18:30 -0700 (PDT) MIME-Version: 1.0 References: <20211019134204.3382645-1-agruenba@redhat.com> In-Reply-To: From: Linus Torvalds Date: Tue, 26 Oct 2021 12:18:14 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v8 00/17] gfs2: Fix mmap + page fault deadlocks To: Catalin Marinas , Harry Wentland , Leo Li , Alex Deucher , =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Andreas Gruenbacher , Paul Mackerras , Alexander Viro , Christoph Hellwig , "Darrick J. Wong" , Jan Kara , Matthew Wilcox , cluster-devel , linux-fsdevel , Linux Kernel Mailing List , ocfs2-devel@oss.oracle.com, kvm-ppc@vger.kernel.org, linux-btrfs Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 26, 2021 at 11:50 AM Linus Torvalds wrote: > > Because for _most_ cases of "copy_to/from_user()" and friends by far, > the only thing we look for is "zero for success". Gaah. Looking around, I almost immediately found some really odd exceptions to this. Like parse_write_buffer_into_params() in amdgpu_dm_debugfs.c, which does r = copy_from_user(wr_buf_ptr, buf, wr_buf_size); /* r is bytes not be copied */ if (r >= wr_buf_size) { DRM_DEBUG_DRIVER("user data not be read\n"); return -EINVAL; } and allows a partial copy to justy silently succeed, because all the callers have pre-cleared the wr_buf_ptr buffer. I have no idea why the code does that - it seems to imply that user space could give an invalid 'size' parameter and mean to write only the part that didn't succeed. Adding AMD GPU driver people just to point out that this code not only has odd whitespace, but that the pattern for "couldn't copy from user space" should basically always be if (copy_from_user(wr_buf_ptr, buf, wr_buf_size)) return -EFAULT; because if user-space passes in a partially invalid buffer, you generally really shouldn't say "ok, I got part of it and will use that part" There _are_ exceptions. We've had situations where user-space only passes in the pointer to the buffer, but not the size. Bad interface, but it historically happens for the 'mount()' system call 'data' pointer. So then we'll copy "up to a page size". Anyway, there are clearly some crazy users, and converting them all to also check for negative error returns might be more painful than I thought it would be. Linus