Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp527138imu; Wed, 16 Jan 2019 03:14:22 -0800 (PST) X-Google-Smtp-Source: ALg8bN6gJM3o30hqvIYUW34EbkioAqZPJOCBYCEjy0EdaHBIIuSfDCgGMMdzGjfJldurauzxfKlP X-Received: by 2002:a63:4745:: with SMTP id w5mr8490776pgk.377.1547637262802; Wed, 16 Jan 2019 03:14:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547637262; cv=none; d=google.com; s=arc-20160816; b=m36hoCYk53w7OYtieh9+M7+OlOL9tVYcfO7mau628YUiBS/3gOH2//6zvdAGbgyE+0 RGGdPN4AArB2jUZKaep5k4ICmsGGR0GYtAOjFq2XUPTEzDNI6JkSHJBxtWXzG/71eLwR Z+4BzQ2xhgaJ2/PqwtcQQ3W0dPbLNwwoWKhZjaw+TROvMl1SBMWUAUmCKBnnaU2umqa8 jpI+AQZLTQKsbziEDVVwffqKSSUH0r0jhZyZB8Q57Gf6BTU7tHCzqLilaSFa/6HzL9Dn vsWSJR9A6BlG1uaKl9G1xhUDNZhrXZ5or5O8agoluxIlgRtlMROADUaFE0n5Ys6ew8NX 1rAw== 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=aQZwEBQpL1b4DAmbmPA2A/1ORF2JkpS9UeUDI3vnJJE=; b=WGTaxyzVScDkxyYaDjJ/VhVoioX27x6lNpHRhwjAoxgDAaJuXpvcd4BmZc62Ordfvp ATKKLaIAk2q/8NOdCV0LcHn0K1NdV7J5/0HDyQHMQ99AYhEY1trcB5Gh6k2Qhr20pZN4 L3Xil+iuRJ4ZjiCsXIc0xjTaVmN5t6RyfO+z+4yXSzCEScKxGPp6ubbjTNvtVU5G8aPv hXreIuMjjYnWkMueBx3WmPXtXUAhwD4vshxXw0NIgX7WYb7qqtyNdFNMcDPziw1vs0ZU 3/ghkCGZNDsJZjKqUBfRZ7t6y+fZVZMSpmGhLTn+7/vvw4FSHRkItDtvxlapaAHyIjGW YyiA== 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 v184si5502472pgd.295.2019.01.16.03.14.06; Wed, 16 Jan 2019 03:14:22 -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 S2389891AbfAOUfZ (ORCPT + 99 others); Tue, 15 Jan 2019 15:35:25 -0500 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:35967 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729067AbfAOUfZ (ORCPT ); Tue, 15 Jan 2019 15:35:25 -0500 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id x0FKZ3g2007201; Tue, 15 Jan 2019 21:35:03 +0100 Date: Tue, 15 Jan 2019 21:35:03 +0100 From: Willy Tarreau To: Kalle Valo Cc: Silvio Cesare , linux-kernel@vger.kernel.org, Dan Carpenter , Kees Cook , Will Deacon , Greg KH Subject: Re: [PATCH 2/8] libertas: change snprintf to scnprintf for possible overflow Message-ID: <20190115203503.GA7117@1wt.eu> References: <20190112152844.26550-1-w@1wt.eu> <20190112152844.26550-2-w@1wt.eu> <878szma2hz.fsf@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878szma2hz.fsf@codeaurora.org> 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 On Tue, Jan 15, 2019 at 07:55:36AM +0200, Kalle Valo wrote: > Willy Tarreau writes: > > > From: Silvio Cesare > > > > Change snprintf to scnprintf. There are generally two cases where using > > snprintf causes problems. > > > > 1) Uses of size += snprintf(buf, SIZE - size, fmt, ...) > > In this case, if snprintf would have written more characters than what the > > buffer size (SIZE) is, then size will end up larger than SIZE. In later > > uses of snprintf, SIZE - size will result in a negative number, leading > > to problems. Note that size might already be too large by using > > size = snprintf before the code reaches a case of size += snprintf. > > > > 2) If size is ultimately used as a length parameter for a copy back to user > > space, then it will potentially allow for a buffer overflow and information > > disclosure when size is greater than SIZE. When the size is used to index > > the buffer directly, we can have memory corruption. This also means when > > size = snprintf... is used, it may also cause problems since size may become > > large. Copying to userspace is mitigated by the HARDENED_USERCOPY kernel > > configuration. > > > > The solution to these issues is to use scnprintf which returns the number of > > characters actually written to the buffer, so the size variable will never > > exceed SIZE. > > > > Signed-off-by: Silvio Cesare > > Cc: Kalle Valo > > Cc: Dan Carpenter > > Cc: Kees Cook > > Cc: Will Deacon > > Cc: Greg KH > > Signed-off-by: Willy Tarreau > > I don't see any mention about which tree this should go to. Can I take > this to wireless-drivers-next? Possibly. It addresses a small memory disclosure issue when using debugfs, and as such it should probably also be submitted to stable branches, so please use the most suitable tree that doesn't add too much extra delay. Thanks, Willy