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=-4.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 4D14CC433EA for ; Mon, 27 Jul 2020 14:40:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3088820719 for ; Mon, 27 Jul 2020 14:40:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729592AbgG0OkS convert rfc822-to-8bit (ORCPT ); Mon, 27 Jul 2020 10:40:18 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:33215 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729591AbgG0OJP (ORCPT ); Mon, 27 Jul 2020 10:09:15 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-250-GXr1mpTxOlmxyosLYcC-jw-1; Mon, 27 Jul 2020 15:09:11 +0100 X-MC-Unique: GXr1mpTxOlmxyosLYcC-jw-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Mon, 27 Jul 2020 15:09:10 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Mon, 27 Jul 2020 15:09:10 +0100 From: David Laight To: 'Al Viro' CC: 'David Miller' , "hch@lst.de" , "kuba@kernel.org" , "ast@kernel.org" , "daniel@iogearbox.net" , "kuznet@ms2.inr.ac.ru" , "yoshfuji@linux-ipv6.org" , "edumazet@google.com" , "linux-crypto@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "bpf@vger.kernel.org" , "netfilter-devel@vger.kernel.org" , "coreteam@netfilter.org" , "linux-sctp@vger.kernel.org" , "linux-hams@vger.kernel.org" , "linux-bluetooth@vger.kernel.org" , "bridge@lists.linux-foundation.org" , "linux-can@vger.kernel.org" , "dccp@vger.kernel.org" , "linux-decnet-user@lists.sourceforge.net" , "linux-wpan@vger.kernel.org" , "linux-s390@vger.kernel.org" , "mptcp@lists.01.org" , "lvs-devel@vger.kernel.org" , "rds-devel@oss.oracle.com" , "linux-afs@lists.infradead.org" , "tipc-discussion@lists.sourceforge.net" , "linux-x25@vger.kernel.org" Subject: RE: get rid of the address_space override in setsockopt v2 Thread-Topic: get rid of the address_space override in setsockopt v2 Thread-Index: AQHWYgvqDt5Xt3HFu0u82UKLVqcKxKkbLTEQgAA3GQCAABNbQA== Date: Mon, 27 Jul 2020 14:09:09 +0000 Message-ID: <5d958e937db54849b4ef9046e7e12277@AcuMS.aculab.com> References: <20200723060908.50081-1-hch@lst.de> <20200724.154342.1433271593505001306.davem@davemloft.net> <8ae792c27f144d4bb5cbea0c1cce4eed@AcuMS.aculab.com> <20200727134814.GD794331@ZenIV.linux.org.uk> In-Reply-To: <20200727134814.GD794331@ZenIV.linux.org.uk> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org From: Al Viro > Sent: 27 July 2020 14:48 > > On Mon, Jul 27, 2020 at 09:51:45AM +0000, David Laight wrote: > > > I'm sure there is code that processes options in chunks. > > This probably means it is possible to put a chunk boundary > > at the end of userspace and continue processing the very start > > of kernel memory. > > > > At best this faults on the kernel copy code and crashes the system. > > Really? Care to provide some details, or is it another of your "I can't > be possibly arsed to check what I'm saying, but it stands for reason > that..." specials? I did more 'homework' than sometimes :-) Slightly difficult without a searchable net-next tree. However, as has been pointed out is a different thread this code is used to update IPv6 flow labels: > > - if (copy_from_user(fl->opt+1, optval+CMSG_ALIGN(sizeof(*freq)), olen)) > > + sockptr_advance(optval, CMSG_ALIGN(sizeof(*freq))); > > + if (copy_from_sockptr(fl->opt + 1, optval, olen)) > > goto done; and doesn't work because the advances are no longer cumulative. Now access_ok() has to take the base address and length to stop 'running into' kernel space, but the code above can advance from a valid user pointer (which won't fault) to a kernel address. If there were always an unmapped 'guard' page in the user address space the access_ok() check prior to copy_to/from_user() wouldn't need the length. So I surmise that no such guard page exists and so the above can advance from user addresses into kernel ones. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)