Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4408448imu; Mon, 14 Jan 2019 22:40:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN4yFqmGTq3xniFpt8zXdHkRNC+QFKGuxF3aMQWnBmbxbygPYaWx9UCv6FSs6bhINijBKBp3 X-Received: by 2002:a62:ea09:: with SMTP id t9mr2543558pfh.228.1547534430063; Mon, 14 Jan 2019 22:40:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547534430; cv=none; d=google.com; s=arc-20160816; b=gXtMdydyLBymt8v60pO6VgkhQquu9q/L7Xo5by0VkBkwVgypQbuNon8SyyxIUEqJAN uX7jLB5/CVSTPn8wE5Wn7Piylc4nanoXVJasH3s4Uo9ojL9L4LXUhAPoSf4EjfLIaZvn 21HwlMeKcgmeH8rBxZG7yvqBPwyINHQK2r7q71QJtebJ5r4DrUWOvi+qyR4/o7gSIj8l bNt5b5yforhN/B+eg4MgkYEonvJwvBridih2+tgAT6yqvpciVAMjU5ud05wRR8gVjhgB ul3A/NClSn1kpMTuMwD+jeH1Cb9CN23wfD1DJvJ+AqZLHXztFK34dCjOp6kqiS0BZ6gn ZN7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:dmarc-filter :dkim-signature:dkim-signature; bh=6GLk45QJDcy/VSNag29E0iHZXlhpdOztMKW6xLohzwg=; b=V0+xlZnnriJ2JIARASMhVk3q4kRfb/PLbAbO5F6q/ZOD27UXssB6fAzDuOhRW1Uu0w vQn3QSnqifpReffnoo+i5pJxJT+fqbn/VUbR8fDfVU4Bl9H9neyPUFtX3iuY8uxkJebx RR+svU8RaYmOcAvMXwI5kMGJbk9P2KW7lhhsp5BEahofLLP6lsoEP+XjrFM5yf3r7RsG b/TXoxxhIBQI8x6iNTNb9mgyUAUpum5I2BPmTANTIaGpXP/3shw+Sa6KOWGkbajUzx1i Ymjkj11he7xZ4uc/ZNsePDe1AdBMqSk/GJ8OUkOfbOCjVaDaTfmPPrMeRhhPF3hujkSt MPmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=TS9y6zS6; dkim=pass header.i=@codeaurora.org header.s=default header.b=OgmtptBi; 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 21si2415539pge.374.2019.01.14.22.40.14; Mon, 14 Jan 2019 22:40:30 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=TS9y6zS6; dkim=pass header.i=@codeaurora.org header.s=default header.b=OgmtptBi; 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 S1728269AbfAOFzn (ORCPT + 99 others); Tue, 15 Jan 2019 00:55:43 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:54394 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728174AbfAOFzn (ORCPT ); Tue, 15 Jan 2019 00:55:43 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id DDA7C6024C; Tue, 15 Jan 2019 05:55:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1547531741; bh=kuhkdhzCgW4d7scFPgG0rdZ5IKsYRSc4ZVg+67tqgqU=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=TS9y6zS6CsJsFZ8iTfBfheJctdXRy5s/idVayyZCSZ5OuQmjTeef/CQkaS7w0asd9 UTuoJToKw8d0h1LcheMZ7x092IvERX0YaR+lXxgPlE+aJfqPDlP0KNZhettsboClRC 0ux3kJ7QTDSbWc3SILS2yzQOmzjT8y1+yX/OrB3I= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from x230.qca.qualcomm.com (37-136-114-46.rev.dnainternet.fi [37.136.114.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: kvalo@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 0CB2F6024C; Tue, 15 Jan 2019 05:55:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1547531740; bh=kuhkdhzCgW4d7scFPgG0rdZ5IKsYRSc4ZVg+67tqgqU=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=OgmtptBiv8g457Qp/ZcnGmFIY19fTn8jz+sh26D6L+XStC2/PyEwIRIUSd7Y/cf2c ztOwLzzcIftLbBB2b/RA0TdMIoQkRXAJBXa6e9EYt+CW2thZbQQfizuiNREbkF3mzf bx8o7EzjRnGnrGH2EDFh7e28+Q5GARCQO1TunbpE= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 0CB2F6024C Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=kvalo@codeaurora.org From: Kalle Valo To: Willy Tarreau 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 References: <20190112152844.26550-1-w@1wt.eu> <20190112152844.26550-2-w@1wt.eu> Date: Tue, 15 Jan 2019 07:55:36 +0200 In-Reply-To: <20190112152844.26550-2-w@1wt.eu> (Willy Tarreau's message of "Sat, 12 Jan 2019 16:28:38 +0100") Message-ID: <878szma2hz.fsf@codeaurora.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? -- Kalle Valo