Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1208342imu; Wed, 28 Nov 2018 06:17:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/UsnYwd6WJuJzXqkEabOcxiAcoco6/TZuIR4lGjIus++7kELlyWM/JoaraYCpCADLpHYaKe X-Received: by 2002:a65:6215:: with SMTP id d21mr33309471pgv.289.1543414667562; Wed, 28 Nov 2018 06:17:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543414667; cv=none; d=google.com; s=arc-20160816; b=jX3wISIotzo2I8nXw5ziwueGt8pu9NaXCzmUQpmZUYb2dSQ+6Zu5faoTA3mk5jU5Dy trrK5xBYWOZU1zWXYq/32PDhvixTFogkRhmwyThs0AF/UG1vjfPeMa5P/y9N2yXon609 3aVRbKxM6vz4VSAf+Agji+qa84dpu89CJcCFh9yPrHif1lMTIYbH0Vae9P3PBBSHNunX JpYBWhIhHOZfVv0jW8q0hqwuLN2jLHunftcMookkLMXMHEPxK8LdNKYySL5CQz3jjvbi HZkIfkenBEpUzti/LsnmPMOQfDXGygp9bsMIJXElUB5uSBtihdIAih6lpr0mr7aIUjCX yINA== 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:to :from:date; bh=MFfKiN2jwUP7j0ywEyxZewWiMwWXIJMlrLzuNAd4foA=; b=UuXH9l4noQUKwPZmOvr+OciAnkv+v5uiEpKGjjKK3Yqz5+9vCHZZMDO3bf5LNYbOn7 9LdhGXkw9sgAarNhaT8JTqYS0O6qUtbH9W1n2XOuiIl77xJpoYVrTe3Jsf3T4FAtFoxT qJCK9rAQZm+UDM6qcOClnoxaNTchZhM2gjeOQuIwG12Ofn+MTsgwzlArEbpvQvKQTWCx IYb+37GpHinapDx1OzuHLHEl42yqRC4thOPoJ1SbYsRqGuu6fdPk5EO3GKy/PBV96JDo fLkmMAyjvCE8xRrbrhOZgz29GmQB6vdyfOdUB0eHtrmOScfdc1/0D5FrsBLTx3Sn7p/h Drqw== 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 m39si7956251plg.315.2018.11.28.06.17.31; Wed, 28 Nov 2018 06:17:47 -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 S1728116AbeK2BRt (ORCPT + 99 others); Wed, 28 Nov 2018 20:17:49 -0500 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:49665 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727823AbeK2BRt (ORCPT ); Wed, 28 Nov 2018 20:17:49 -0500 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id wASEFlgJ020544; Wed, 28 Nov 2018 15:15:47 +0100 Date: Wed, 28 Nov 2018 15:15:47 +0100 From: Willy Tarreau To: dsterba@suse.cz, Yueyi Li , "gregkh@linuxfoundation.org" , "donb@securitymouse.com" , "linux-kernel@vger.kernel.org" , markus@oberhumer.com Subject: Re: [PATCH v2] lzo: fix ip overrun during compress. Message-ID: <20181128141547.GD20409@1wt.eu> References: <20181128135242.gy3avmbp2pdmjaka@twin.jikos.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181128135242.gy3avmbp2pdmjaka@twin.jikos.cz> User-Agent: Mutt/1.6.1 (2016-04-27) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi David, On Wed, Nov 28, 2018 at 02:52:42PM +0100, David Sterba wrote: > The fix is adding a few branches to code that's supposed to be as fast > as possible. The branches would be evaluated all the time while > protecting against one signle bad page address. This does not look like > a good performance tradeoff. That was my concern as well, though the simplified test should be cheaper especially since the branch is (almost) never taken and easily predicted. > > +#define OVERFLOW_ADD_CHECK(a, b) \ > > + (((a) + (b)) < (a)) > > I'm not sure if this is generally safe overflow check (never not > optimized out). Here it depends on the types of 'a' and 'b' that are > pointer (ip) and size_t (m_len). GCC has __builtin_add_overflow_p so > that one should be used where possible. Sure but that one came with gcc 7 which is not exactly a reasonable prerequisite especially when it comes to stable kernels. However I'm now seeing that we have include/linux/overflow.h which provides this. I have not checked what versions support it though, but 4.14 already doesn't have it. Thus a fallback will be needed anyway and maintaining two versions is not exactly the best thing to have to do :-/ Willy