From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0776C388F7 for ; Thu, 22 Oct 2020 19:05:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62FA424658 for ; Thu, 22 Oct 2020 19:05:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KQqTFOK8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S369871AbgJVTFJ (ORCPT ); Thu, 22 Oct 2020 15:05:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S369863AbgJVTFH (ORCPT ); Thu, 22 Oct 2020 15:05:07 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0E7BC0613D6 for ; Thu, 22 Oct 2020 12:05:04 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id bh6so1462584plb.5 for ; Thu, 22 Oct 2020 12:05:04 -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=Ob2vCJvO6llStuDKjUpnqeOT2ObygH+mOzcnW04eANY=; b=KQqTFOK8RfeQlRsCMQ+rOlUOsaIw3aFT2tl0EvIIitPh93BRypnBq10dbZ1VQInVA9 YBqadNAg8WpA2s2M51/9SZIy6oP0pnbbWbfMb7wIWJV2snjJBMbyo5oSDcHw4N1zr7/S VZLvINfglpSloiYKbOwAZRZgsEq5EwVd6j156C6w/ZUnsQNcPlNYKpHJP5uI2nd5y9vn Eb462d8qlKbplpH5u1WCwEWQN9mxoYO0QRuuyd1KRKvAJJWpZKPK5rzGEmieFY4kQrsm FHET+zmyltpbQH7fuqtpyH09Ge3zLiQZSD5eVuK163dQLFMNQGhprwY4hoqO0xWMFeFJ fZNQ== 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=Ob2vCJvO6llStuDKjUpnqeOT2ObygH+mOzcnW04eANY=; b=k1r0FQY+MKPtyIlYEE4LZsNFgCE6+X16WA85LZVwBGarPETNpkxrKkBRBS3yBpRkpR aHaHMWj7yvz28d1jDVzJpKdQps2MGk3yjYySv0VvjFT9VnsiamIH5aI6110RxEupf1Jz 2RrOf0nuC8a2pzOp+cXCQaaGzeSPfic47sKTQbeEWfLxXA4v/tKNjFfDT2fbz5oZUx9G r+/1GGO1wB7SVuTNiuF+c2/hOr/p4r0TqMSmiivnKMNG1LB4kPJ0JUTEm2ejzIMwj4Se ELtoEWGBy7OuuPMdzYII3EFPSzP+hQxX/Mk/rRmzVq0WhSDhr30VPrxvQoSsjQ39nGC9 bpvA== X-Gm-Message-State: AOAM5305tkuB35a1DDq1/VOFBN+IEB6XJAkyP1G+hIRYlu3RGwW73BQ0 /Dtopiqh1xXPS7dgxu3ss+T24eidZkpRLrYxnHR8Kg== X-Google-Smtp-Source: ABdhPJywMCKq0vfUuAKWQ9RLmH3NxEeoaMuMMn+wDHsffqxkAqXyKJ4o6MiCnyTmuBnnGxJWFn5poUUGRnshTJa4lRY= X-Received: by 2002:a17:902:c40b:b029:d3:def2:d90f with SMTP id k11-20020a170902c40bb02900d3def2d90fmr3608595plk.29.1603393503931; Thu, 22 Oct 2020 12:05:03 -0700 (PDT) MIME-Version: 1.0 References: <20201021233914.GR3576660@ZenIV.linux.org.uk> <20201022082654.GA1477657@kroah.com> <80a2e5fa-718a-8433-1ab0-dd5b3e3b5416@redhat.com> <5d2ecb24db1e415b8ff88261435386ec@AcuMS.aculab.com> <20201022090155.GA1483166@kroah.com> <5fd6003b-55a6-2c3c-9a28-8fd3a575ca78@redhat.com> <20201022132342.GB8781@lst.de> <8f1fff0c358b4b669d51cc80098dbba1@AcuMS.aculab.com> In-Reply-To: From: Nick Desaulniers Date: Thu, 22 Oct 2020 12:04:52 -0700 Message-ID: Subject: Re: Buggy commit tracked to: "Re: [PATCH 2/9] iov_iter: move rw_copy_check_uvector() into lib/iov_iter.c" To: Arnd Bergmann Cc: David Laight , Christoph Hellwig , David Hildenbrand , Greg KH , Al Viro , "kernel-team@android.com" , Andrew Morton , Jens Axboe , David Howells , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-mips@vger.kernel.org" , "linux-parisc@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "linux-s390@vger.kernel.org" , "sparclinux@vger.kernel.org" , "linux-block@vger.kernel.org" , "linux-scsi@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-aio@kvack.org" , "io-uring@vger.kernel.org" , "linux-arch@vger.kernel.org" , "linux-mm@kvack.org" , "netdev@vger.kernel.org" , "keyrings@vger.kernel.org" , "linux-security-module@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org On Thu, Oct 22, 2020 at 11:13 AM Arnd Bergmann wrote: > > On Thu, Oct 22, 2020 at 7:54 PM Nick Desaulniers > wrote: > > On Thu, Oct 22, 2020 at 9:35 AM David Laight wrote: > > > > > > Which makes it a bug in the kernel C syscall wrappers. > > > They need to explicitly mask the high bits of 32bit > > > arguments on arm64 but not x86-64. > > > > Why not x86-64? Wouldn't it be *any* LP64 ISA? > > x86-64 is slightly special because most instructions on a 32-bit > argument clear the upper 32 bits, while on most architectures > the same instruction would leave the upper bits unchanged. Oh interesting, depends on the operations too on x86_64 IIUC? > > > Attaching a patch that uses the proper width, but I'm pretty sure > > there's still a signedness issue . Greg, would you mind running this > > through the wringer? > > I would not expect this to change anything for the bug that Greg > is chasing, unless there is also a bug in clang. > > In the version before the patch, we get a 64-bit argument from > user space, which may consist of the intended value in the lower > bits plus garbage in the upper bits. However, vlen only gets > passed down into import_iovec() without any other operations > on it, and since import_iovec takes a 32-bit argument, this is > where it finally gets narrowed. Passing an `unsigned long` as an `unsigned int` does no such narrowing: https://godbolt.org/z/TvfMxe (same vice-versa, just tail calls, no masking instructions). So if rw_copy_check_uvector() is inlined into import_iovec() (looking at the mainline@1028ae406999), then children calls of `rw_copy_check_uvector()` will be interpreting the `nr_segs` register unmodified, ie. garbage in the upper 32b. > > After your patch, the SYSCALL_DEFINE3() does the narrowing > conversion with the same clearing of the upper bits. > > If there is a problem somewhere leading up to import_iovec(), > it would have to in some code that expects to get a 32-bit > register argument but gets called with a register that has > garbage in the upper bits /without/ going through a correct > sanitizing function like SYSCALL_DEFINE3(). > > Arnd -- Thanks, ~Nick Desaulniers