Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1995780imu; Fri, 14 Dec 2018 04:14:21 -0800 (PST) X-Google-Smtp-Source: AFSGD/UP7a4WTNmvhoqtS5Gn2/cxBGc/HXjs/ABlMBeJq3cCQEc/mA6VVSqgDrDJ1WdTEAgmnNxY X-Received: by 2002:a63:5c22:: with SMTP id q34mr2455063pgb.417.1544789661656; Fri, 14 Dec 2018 04:14:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789661; cv=none; d=google.com; s=arc-20160816; b=A551YNUs63pk6QT6COha7yL46r1x8QKO850ffI2AeA+lQAp6ou0CnHg3/0+qjlIBz6 c+zqI0y+Ukk3ub9gc7Rr9VFBHRCGzaqqlLsRFy9ZyMzHsBx3e4u9YFCg2uf/yFujkvLf tSjBD5vaKwlj7e8YW3UTEA1rdYqB6Al58wL2xnpllpRrlU2Rg3JKv5fMXa3AoXXXx0Fc 1jidWoyJz5i5XeB7nefoP8Y6TUr0djt8M2DbFVpHPo5TXgw2gZl3VFWGgjI+Av2+mbf2 gouP7kGIA/ttJgs/cg99lQw2M0eWGbrOrR2xsDXAGeg6VCJtiogJF0BZnkeikKm1ibGk 9Nzg== 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=U7bLUT7jLpS+x0yfBT0i+l28cYGR1hVJfF5vySntLYg=; b=HarpQC9ovBFzhIHz9S50/VGplLUBeMq5mcWcoWEKH272Hf+6/m3mUzdFUXY+5aTkUO 0PTZAvt9soV6XJ7bA6U0YNuog8LN8thhJ18A0fIkn08Q8PLvU80z/1MAd1dcevgEwhr+ zwqzGqpZDHhcSG8Ui4kb24tOQyZ7PdYnXvB/opX2x6tFAyXGdt9wbCKtwOr8CSQKHvxy 6uY2tWEkIIUB9Ig+2Tw2pG6qjTYbzxqJJzfktbyY8dPlqNZhPaTI+lvgEo64ulsJWOq4 aqit3YnL5L/ILyje6mZcNm7DKJYNgWMv3b4PWkwFD7gdCZN42Rg7Dq1lEtig9mkaEKjx KdJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mW3xQFE5; 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 z12si3783537plk.90.2018.12.14.04.14.06; Fri, 14 Dec 2018 04:14:21 -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=mW3xQFE5; 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 S1731904AbeLNMMO (ORCPT + 99 others); Fri, 14 Dec 2018 07:12:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:59198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726670AbeLNMMJ (ORCPT ); Fri, 14 Dec 2018 07:12:09 -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 CFC272133F; Fri, 14 Dec 2018 12:12:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789528; bh=m7VUbMHqUaQCNJjwo7PzD86SkxEV4xTROhZ1JEWVamQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mW3xQFE5ONVFwm9T+O/ly3h59ZYNXbCK9tJdPKt/2UbFGTBZGW4bHCIx+/hgX57Jl WOU93jA0acf8PaLuIglkzIVirD35CU4ScEPoIBecjRwP8jdEaSaijj56p7A/Ch4dVF incwYtzsoBvmncu9M0dxzGf9XoOFsq0dq3lhbg/o= 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.9 28/51] bpf: fix check of allowed specifiers in bpf_trace_printk Date: Fri, 14 Dec 2018 13:00:30 +0100 Message-Id: <20181214115715.839981643@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115713.244259772@linuxfoundation.org> References: <20181214115713.244259772@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.9-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 41805fb3c661..7cc06f267be5 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