Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp1095889ima; Wed, 6 Feb 2019 13:40:52 -0800 (PST) X-Google-Smtp-Source: AHgI3IbaInzBfBlFOEDzvfoOmE91Gt0hUOISbQtvLKrH4Zk8fHVEI9R3u1k04KBbh+huq4FLyzhc X-Received: by 2002:a63:9712:: with SMTP id n18mr11424323pge.295.1549489252839; Wed, 06 Feb 2019 13:40:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549489252; cv=none; d=google.com; s=arc-20160816; b=CnjLaZzYiE3M6lmk+P3hTuriLV/b9zGz9tWzIo+A9Du7Novvc8xNTS3k31lOBWrdP1 unxpEbyjG/rFxHco7Avgyplr7/IMBtuVyo0jkVL1bQfVW5W2YSnHd9DDEiol9YuNdI31 7gYabb4k+OuJkf51QoeWR3i4WgNBOOGExbscnRC+QLK+WO/VRAhhRcr7AqH3JUleBgJk zdfNpR8V4T3vsQQ9wYF12MwLGbJBpdvqB8QIWULemxaxiVq+WBR1gcQWsO/gDa2ewVcq J+1b6jrYlHoa8/V9ChbxzcF3ly7EI6b1j+PA9zyn+t7sMV5vz3oY9lL30+JTy90VAqXt IDng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=JUm4S3VSj3dyidii0THNiEwwPkc/RTSviqZ5jIElPuo=; b=yoSV36Qgl7LpfWsT/MeIK9/BKRJSCDzg10VAJaaTX/cgjbjRLGEfYA7hkZYtu1fDEb QwGhimNGnCoGKCDDr8ep1u0WJ8OsyKGVap7dSD9CsbKmEg8B0+8revaNEgk8e07JYyex PGykqQEHQs1XLTrtW6aaMn/6NdQuJe10s4uWSlEcaFVQYi0oLwSLCAKcfg0iqXGH8yjC 3HhGh7Va9TcpNfTBdDGs4OOjmYv4jX0stLj7SE7+LcSBDyma5WmWnxSctQxyhmtutlDG MJjbaknKnT9nWb5s4UEsqzRrWubH87OQS22ULjN2urStAdRQAtmZbe2xNEJm+gnMt4cT z65w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cb16si2969839plb.290.2019.02.06.13.40.36; Wed, 06 Feb 2019 13:40:52 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726565AbfBFVka (ORCPT + 99 others); Wed, 6 Feb 2019 16:40:30 -0500 Received: from charlotte.tuxdriver.com ([70.61.120.58]:34447 "EHLO smtp.tuxdriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725983AbfBFVka (ORCPT ); Wed, 6 Feb 2019 16:40:30 -0500 Received: from cpe-2606-a000-111b-405a-9816-2c85-c514-8f7a.dyn6.twc.com ([2606:a000:111b:405a:9816:2c85:c514:8f7a] helo=localhost) by smtp.tuxdriver.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1grUvd-0007R4-F6; Wed, 06 Feb 2019 16:40:25 -0500 Date: Wed, 6 Feb 2019 16:39:48 -0500 From: Neil Horman To: Julien Gomes Cc: Marcelo Ricardo Leitner , netdev@vger.kernel.org, linux-sctp@vger.kernel.org, linux-kernel@vger.kernel.org, davem@davemloft.net, vyasevich@gmail.com, lucien.xin@gmail.com Subject: Re: [PATCH net] sctp: make sctp_setsockopt_events() less strict about the option length Message-ID: <20190206213948.GE16887@hmswarspite.think-freely.org> References: <20190206201430.18830-1-julien@arista.com> <20190206203754.GC13621@localhost.localdomain> <20190206210723.GD13621@localhost.localdomain> <274c48cb-7590-682b-f4de-f5c4ce2d2144@arista.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <274c48cb-7590-682b-f4de-f5c4ce2d2144@arista.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Score: -2.9 (--) X-Spam-Status: No Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 06, 2019 at 01:26:55PM -0800, Julien Gomes wrote: > > > On 2/6/19 1:07 PM, Marcelo Ricardo Leitner wrote: > > On Wed, Feb 06, 2019 at 12:48:38PM -0800, Julien Gomes wrote: > >> > >> > >> On 2/6/19 12:37 PM, Marcelo Ricardo Leitner wrote: > >>> On Wed, Feb 06, 2019 at 12:14:30PM -0800, Julien Gomes wrote: > >>>> Make sctp_setsockopt_events() able to accept sctp_event_subscribe > >>>> structures longer than the current definitions. > >>>> > >>>> This should prevent unjustified setsockopt() failures due to struct > >>>> sctp_event_subscribe extensions (as in 4.11 and 4.12) when using > >>>> binaries that should be compatible, but were built with later kernel > >>>> uapi headers. > >>> > >>> Not sure if we support backwards compatibility like this? > >>> > >>> My issue with this change is that by doing this, application will have > >>> no clue if the new bits were ignored or not and it may think that an > >>> event is enabled while it is not. > >>> > >>> A workaround would be to do a getsockopt and check the size that was > >>> returned. But then, it might as well use the right struct here in the > >>> first place. > >>> > >>> I'm seeing current implementation as an implicitly versioned argument: > >>> it will always accept setsockopt calls with an old struct (v4.11 or > >>> v4.12), but if the user tries to use v3 on a v1-only system, it will > >>> be rejected. Pretty much like using a newer setsockopt on an old > >>> system. > >> > >> With the current implementation, given sources that say are supposed to > >> run on a 4.9 kernel (no use of any newer field added in 4.11 or 4.12), > >> we can't rebuild the exact same sources on a 4.19 kernel and still run > >> them on 4.9 without messing with structures re-definition. > > > > Maybe what we want(ed) here then is explicit versioning, to have the 3 > > definitions available. Then the application is able to use, say struct > > sctp_event_subscribe, and be happy with it, while there is struct > > sctp_event_subscribe_v2 and struct sctp_event_subscribe_v3 there too. > > > > But it's too late for that now because that would break applications > > already using the new fields in sctp_event_subscribe. > > Right. > > > > >> > >> I understand your point, but this still looks like a sort of uapi > >> breakage to me. > > > > Not disagreeing. I really just don't know how supported that is. > > Willing to know so I can pay more attention to this on future changes. > > > > Btw, is this the only occurrence? > > Can't really say, this is one I witnessed, I haven't really looked for > others. > > > > >> > >> > >> I also had another way to work-around this in mind, by copying optlen > >> bytes and checking that any additional field (not included in the > >> "current" kernel structure definition) is not set, returning EINVAL in > >> such case to keep a similar to current behavior. > >> The issue with this is that I didn't find a suitable (ie not totally > >> arbitrary such as "twice the existing structure size") upper limit to > >> optlen. > > > > Seems interesting. Why would it need that upper limit to optlen? > > > > Say struct v1 had 4 bytes, v3 now had 12. The user supplies 12 bytes > > to the kernel that only knows about 4 bytes. It can check that (12-4) > > bytes in the end, make sure no bit is on and use only the first 4. > > > > The fact that it was 12 or 200 shouldn't matter, should it? As long as > > the (200-4) bytes are 0'ed, only the first 4 will be used and it > > should be ok, otherwise EINVAL. No need to know how big the current > > current actually is because it wouldn't be validating that here: just > > that it can safely use the first 4 bytes. > > The upper limit concern is more regarding the call to copy_from_user > with an unrestricted/unchecked value. Copy_from_user should be safe to copy an arbitrary amount, the only restriction is that optlen can't exceed the size of the buffer receiving the data in the kernel. From that standpoint your patch is safe. However, that exposes the problem of checking any tail data on the userspace buffer. That is to say, if you want to ensure that any extra data that gets sent from userspace isn't 'set', you would have to copy that extra data in consumable chunks and check them individaully, and that screams DOS to me (i.e. imagine a user passing in a 4GB buffer, and having to wait for the kernel to copy each X sized chunk, looking for non-zero values). > I am not sure of how much of a risk/how exploitable this could be, > that's why I cautiously wanted to limit it in the first place just in case. > > > > >> > >>> > >>>> > >>>> Signed-off-by: Julien Gomes > >>>> --- > >>>> net/sctp/socket.c | 2 +- > >>>> 1 file changed, 1 insertion(+), 1 deletion(-) > >>>> > >>>> diff --git a/net/sctp/socket.c b/net/sctp/socket.c > >>>> index 9644bdc8e85c..f9717e2789da 100644 > >>>> --- a/net/sctp/socket.c > >>>> +++ b/net/sctp/socket.c > >>>> @@ -2311,7 +2311,7 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval, > >>>> int i; > >>>> > >>>> if (optlen > sizeof(struct sctp_event_subscribe)) > >>>> - return -EINVAL; > >>>> + optlen = sizeof(struct sctp_event_subscribe); > >>>> > >>>> if (copy_from_user(&subscribe, optval, optlen)) > >>>> return -EFAULT; > >>>> -- > >>>> 2.20.1 > >>>> > >> > > -- > Julien Gomes >