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 B50F7C388F9 for ; Thu, 22 Oct 2020 20:11:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BA4A24640 for ; Thu, 22 Oct 2020 20:11:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vObNVdN2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2506545AbgJVUL2 (ORCPT ); Thu, 22 Oct 2020 16:11:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2506693AbgJVUL2 (ORCPT ); Thu, 22 Oct 2020 16:11:28 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99C8FC0613D8 for ; Thu, 22 Oct 2020 13:11:27 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id 144so1905168pfb.4 for ; Thu, 22 Oct 2020 13:11:27 -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=GumHU2X+g85YksdsSI4rtK9zksU56rVy/CgxVuW0jEM=; b=vObNVdN2VFhAojESuCXkrxhn1YIwWVv+1XhIW4tZBL+fxMiFOMf/wpbwdQdbTEuqzU didUUL5vkJxiQnySAkNm5bA5dzi4HDPRY/b2q9PCHYr38o1QdWg4eoCCMy0LZ69odEBE EeVL+yKYldv1+Aa2ZS3w6i1XFzR6cyTrr6WpyCHfwh/bI39Aml+4GPRR3PK53sN4m6b3 rUVDazS3OFa6481GJ9+htMab1H1YbLsr5SViapf30nhQCEj8D6AxmtXaycQnaAAFnPK+ ve/0E2puLZtKaH/rY1wRoNU3uLbs1Hp/JNHjorNUJ0gL9lCRxpciXdv4OO2qkM+X3ZVh gy/g== 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=GumHU2X+g85YksdsSI4rtK9zksU56rVy/CgxVuW0jEM=; b=Mr4o+mXtEiZlhCiBjTd89ipcldRM0gq0E9zvBR2Ossx209z5/GNnMXE2CIYLvF30sy 0ePKN8Tn2D+wbw+WJhgOpWB7a2yxmhR2vRi4e1SuIAHGuBQNvonr2p3wP8FsL9mUGeau qbu+eyV/Zy9JAKmLXepnXZkKz/3VM+V5um/wKuG9R5r4vv0imXR7ZUaAKw94HPwSDlj5 u+CZooJ2wf2XvevczxWbIZufesFn/omAOSBFEOHzm2lP0XsdkS37L7ZrsQrQ7Eeesmjf fAmZJ4XhYMgtV4mZZd8S6U3vUDd3vJhdHVQxWN9U94YaA5ZBrt61wSlOfZw3m65apuCD alAQ== X-Gm-Message-State: AOAM533N77MzLCEdAjXTd+8EeEWhRspbkPuZj73C/602AUFHZwZ/xRtW cf9lH1wK6x9UH4L2FbJ30U+/0erT6Nux8OzPwZ0l3g== X-Google-Smtp-Source: ABdhPJzJwPfOlPnqmI7/5P7ibjxaxjQ3K/49C5Uiz6yY7FpMEBFECdyjYA4Y8meqnBbTveKDbTZgpESx4RovmeoudXg= X-Received: by 2002:a17:90a:740a:: with SMTP id a10mr3865197pjg.32.1603397486718; Thu, 22 Oct 2020 13:11:26 -0700 (PDT) MIME-Version: 1.0 References: <20201022090155.GA1483166@kroah.com> <5fd6003b-55a6-2c3c-9a28-8fd3a575ca78@redhat.com> <20201022132342.GB8781@lst.de> <8f1fff0c358b4b669d51cc80098dbba1@AcuMS.aculab.com> <20201022192458.GV3576660@ZenIV.linux.org.uk> In-Reply-To: <20201022192458.GV3576660@ZenIV.linux.org.uk> From: Nick Desaulniers Date: Thu, 22 Oct 2020 13:11:14 -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: Al Viro Cc: Arnd Bergmann , David Laight , Christoph Hellwig , David Hildenbrand , Greg KH , "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 12:25 PM Al Viro wrote: > > On Thu, Oct 22, 2020 at 12:04:52PM -0700, Nick Desaulniers wrote: > > > 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. > > FWIW, > > void f(unsinged long v) > { > if (v != 1) > printf("failed\n"); > } > > void g(unsigned int v) > { > f(v); > } > > void h(unsigned long v) > { > g(v); > } > > main() > { > h(0x100000001); > } A good/analogous example, but things get weird when the leaf node in the call chain is inline asm: https://godbolt.org/z/s19TY5 (I'm not sure that's precisely what's going on here; I'll need to dive more into the calls rw_copy_check_uvector() makes to see if there's inline asm somewhere, pretty sure calls to get_user with `nr_regs` exist). > > must not produce any output on a host with 32bit int and 64bit long, regardless of > the inlining, having functions live in different compilation units, etc. > > Depending upon the calling conventions, compiler might do truncation in caller or > in a callee, but it must be done _somewhere_. -- Thanks, ~Nick Desaulniers