Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3011944imm; Sun, 1 Jul 2018 10:16:11 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfMNwTpwWpWZ/QLL5uO1U7kCfJw4bYdFrUBESPV/ZDhRK9RmPSWRt5luxDVTNtF12PObHXk X-Received: by 2002:a62:d646:: with SMTP id r67-v6mr11872546pfg.130.1530465371351; Sun, 01 Jul 2018 10:16:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530465371; cv=none; d=google.com; s=arc-20160816; b=y+uyFRAg7Dln4v/XxpVFQNkuHy3HdiCXvJ6hacRULgm/sGdnKfuLZmnPupm3TW0fw2 loX7Uo8goKjEy9hwYa2Aeok6CQ3KAOyvBb0tg+lDBuiSl3Aci2oxpGH+2bRhUFpyEVmn RgMhJSFgezPW5OXVglpMollOemCbOy/12Sf9y/sFTcCCimV8JBCJ1TwN+n3ArzSog9dJ dSSOzrT5xc01Ox6/OAxoobNmQLVSi8WBzehpNwT85Zg6BoJ3GY6KuVbfAK9+lIOJQTbp 3FxAAIpVlv1+4fI9aF9p0sUYlQmNvoJWjkjPpPxOzUZxzzxuksCezZV6ry/r9Nwt12I6 jqTQ== 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:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Y3g5+VUG/Lly1618KSF/1mW91KSZXMnzA0jdbzyOXb4=; b=Wu+ZiWYP+U/4lJ+dC4ZdMTIY/vJzOGmGD+DmPWiBhpxPVmcFFp8M6vmfnSpTNuIwuY Rhb/t1E/ipe2D4fDx6YBvCwoN4KYQReoK5EHjQub9GTDXXjJIqzTt4x/dXoDfBApNKfM 8XwxMKCm10M2aP7rxIESVXnLc7HyGEUNo0Rq62oMPHePZewTKLKpnBYUZL1chOaCxarg ztM5rXs293p1LetXMofr+N8V0ppPI90dLdxfDXXNyr9MZtzA+R34xmtGNf40v1cdyw9n /hrVzLe/hq3wXbD34zKbRZaMYUfj1z5Jb7nYETwPjIcHRi71+ImpkD/tBu1dAysgxG+g 5QDg== 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 p18-v6si14139960pfe.150.2018.07.01.10.15.56; Sun, 01 Jul 2018 10:16:11 -0700 (PDT) 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 S1031830AbeGAQj7 (ORCPT + 99 others); Sun, 1 Jul 2018 12:39:59 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37044 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031818AbeGAQj4 (ORCPT ); Sun, 1 Jul 2018 12:39:56 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8E5F2ACC; Sun, 1 Jul 2018 16:39:55 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Zijlstra , Steven Rostedt , dvyukov@google.com, syzkaller@googlegroups.com, fengguang.wu@intel.com, Tetsuo Handa , Sergey Senozhatsky , Petr Mladek Subject: [PATCH 4.17 039/220] printk: fix possible reuse of va_list variable Date: Sun, 1 Jul 2018 18:21:03 +0200 Message-Id: <20180701160909.962246295@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160908.272447118@linuxfoundation.org> References: <20180701160908.272447118@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tetsuo Handa commit 988a35f8da1dec5a8cd2788054d1e717be61bf25 upstream. I noticed that there is a possibility that printk_safe_log_store() causes kernel oops because "args" parameter is passed to vsnprintf() again when atomic_cmpxchg() detected that we raced. Fix this by using va_copy(). Link: http://lkml.kernel.org/r/201805112002.GIF21216.OFVHFOMLJtQFSO@I-love.SAKURA.ne.jp Cc: Peter Zijlstra Cc: Steven Rostedt Cc: dvyukov@google.com Cc: syzkaller@googlegroups.com Cc: fengguang.wu@intel.com Cc: linux-kernel@vger.kernel.org Signed-off-by: Tetsuo Handa Fixes: 42a0bb3f71383b45 ("printk/nmi: generic solution for safe printk in NMI") Cc: 4.7+ # v4.7+ Reviewed-by: Sergey Senozhatsky Signed-off-by: Petr Mladek Signed-off-by: Greg Kroah-Hartman --- kernel/printk/printk_safe.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/kernel/printk/printk_safe.c +++ b/kernel/printk/printk_safe.c @@ -82,6 +82,7 @@ static __printf(2, 0) int printk_safe_lo { int add; size_t len; + va_list ap; again: len = atomic_read(&s->len); @@ -100,7 +101,9 @@ again: if (!len) smp_rmb(); - add = vscnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, args); + va_copy(ap, args); + add = vscnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, ap); + va_end(ap); if (!add) return 0;