Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2014621imu; Fri, 14 Dec 2018 04:31:58 -0800 (PST) X-Google-Smtp-Source: AFSGD/WqZIBeZZ3srMWAP3g31QTqXkyrKrSmH2CDWcxKbsCwlhMuBAyvG2FfWhYDyI6agxeFEb+Q X-Received: by 2002:a17:902:7c82:: with SMTP id y2mr2675334pll.33.1544790718002; Fri, 14 Dec 2018 04:31:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544790717; cv=none; d=google.com; s=arc-20160816; b=eAvuzjAjKivar+RADQ5FwMWja7713sMzVfOnJvDRDtAEgVJVfV9rYRjXNytYVngppk rb2hquhpeVwZtGCQi/HKDWGdS7CsV2BrhIq1mwsMUM9atLJo6HXcuhbPMOr7XsITitIs M1CAfHvBKFIwDVwj7BaqeCC4Mlv8zBMH9HQ28gG9VW8+uuUdY77f9tmO0zMl++nWj5jz fiqW48dgakbRHSC6lS7NZ1/TUBddbTqan1ZTvRbWpi7bt5AqSV+3nffeCpIPhe9kNkEC FJutSIV6JmHrlraBMtpCDVV3HhkYneBt36Eo6Wdi6IjfOO5ynvAsAz0pwx3Xix3mxpzM ejcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=b1pg8UV30waLv8e2JYy+UkAotgv/5CVbXyUu9o5mJwo=; b=C89oZWjr31uY63jTk91I5szEGtHODC0c6n/0Uqolp+m6cf4ylBL9Er+9AFKJHtOLkW ySt090ZHlpoff7xokTAgMyJoVxGGQTWgr+MdGn9mP384e73S7AtyJsbsToU2Xgcvb4r6 T0qPcmc6uac77n044kPrUZzLkpR+dklNJFenUcUtAdFQNBv/0oqLeKWwQl208LnpDtNL A+ExAk2gvK9FbQgZxvCBsueP/ERE80TrvPqX3L9aK5x+u/8QB7/+pp/hwcefMuBX6GPK pmQB4sTma7ME9E5ZiXJqjyLPkXsZ/jqqo34JgWF1NnhCoo0t1kNcKQMzcTasNU+f9yMn ZPKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=avdmKEBd; 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 z22si3861716plo.202.2018.12.14.04.31.42; Fri, 14 Dec 2018 04:31:57 -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=@kernel.org header.s=default header.b=avdmKEBd; 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 S1731553AbeLNMKC (ORCPT + 99 others); Fri, 14 Dec 2018 07:10:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:55780 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731542AbeLNMKA (ORCPT ); Fri, 14 Dec 2018 07:10:00 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B0DE1214DE; Fri, 14 Dec 2018 12:09:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789400; bh=DBEF/xBM9PXIg9AOMwLI7z2CJpMt9Q0Ggg+PxFNQsJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=avdmKEBd5taKA5qQQ2rcNzZ7w66ATbzqjEXAQ7hQ1H1tsi3W8plgoMBk+aiLMTiKE 5u7CDk0LDllhz2xOwWtyJTMVvptSQUTGrnQZAB3CeMIRV9LMnFCc8+WwBJajeebVRZ 7kvaNUWZnRdjo7aoVM7JGNl72/tL8fuXOWaaQTAg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+1ec5c5ec949c4adaa0c4@syzkaller.appspotmail.com, Martynas Pumputis , Daniel Borkmann , Sasha Levin Subject: [PATCH 4.14 45/89] bpf: fix check of allowed specifiers in bpf_trace_printk Date: Fri, 14 Dec 2018 12:59:58 +0100 Message-Id: <20181214115731.908325384@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115729.658859279@linuxfoundation.org> References: <20181214115729.658859279@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 1efb6ee3edea57f57f9fb05dba8dcb3f7333f61f ] A format string consisting of "%p" or "%s" followed by an invalid specifier (e.g. "%p%\n" or "%s%") could pass the check which would make format_decode (lib/vsprintf.c) to warn. Fixes: 9c959c863f82 ("tracing: Allow BPF programs to call bpf_trace_printk()") Reported-by: syzbot+1ec5c5ec949c4adaa0c4@syzkaller.appspotmail.com Signed-off-by: Martynas Pumputis Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- kernel/trace/bpf_trace.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 6350f64d5aa4..f9dd8fd055a6 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -161,11 +161,13 @@ BPF_CALL_5(bpf_trace_printk, char *, fmt, u32, fmt_size, u64, arg1, i++; } else if (fmt[i] == 'p' || fmt[i] == 's') { mod[fmt_cnt]++; - i++; - if (!isspace(fmt[i]) && !ispunct(fmt[i]) && fmt[i] != 0) + /* disallow any further format extensions */ + if (fmt[i + 1] != 0 && + !isspace(fmt[i + 1]) && + !ispunct(fmt[i + 1])) return -EINVAL; fmt_cnt++; - if (fmt[i - 1] == 's') { + if (fmt[i] == 's') { if (str_seen) /* allow only one '%s' per fmt string */ return -EINVAL; -- 2.19.1