From patchwork Mon Jul 16 22:01:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1202541 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id CEA73E0038 for ; Mon, 16 Jul 2012 22:01:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753729Ab2GPWBG (ORCPT ); Mon, 16 Jul 2012 18:01:06 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:48791 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753458Ab2GPWBC (ORCPT ); Mon, 16 Jul 2012 18:01:02 -0400 Received: by wibhr14 with SMTP id hr14so3158728wib.1 for ; Mon, 16 Jul 2012 15:01:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=FOvR2tAU8gHI10TspssUWnfOXUX7fQyPHLDmYpzZouQ=; b=jI9qBQmjMg55G9GQly4ibGdBQgJS5ZJv2X/gO0vJAj9Rd6irsy/LM+ctuGFw+e0vqg d1gL4pVXz9UC2N8LwPtNDCAc1rEz3Yb+6cr9ewQva0tV73zYo7PdRWV9nDSSL8T6Qjlx oYXDDTQo1aCV120SrPCrRuvkkgprS8bFIwvkHr7Imzu6aTYSZtY0Pq9U3kur2od+aFmR I3rA6GdN4xt6iRefLR7Giw5zBC/eMiBlgP0NwVYDYdRklzVImiEtcnrz7DhpOvVtfP5k zFlObCVmtEBM5nf0D2VkKiQtnSCCVyaS4VXqvlopBpO2I0b83lOumHTRHXcLclu7aZAI +yHg== Received: by 10.216.234.100 with SMTP id r78mr6644168weq.107.1342476060113; Mon, 16 Jul 2012 15:01:00 -0700 (PDT) Received: from localhost.localdomain ([95.75.28.223]) by mx.google.com with ESMTPS id o2sm34867334wiz.11.2012.07.16.15.00.54 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 Jul 2012 15:00:58 -0700 (PDT) From: Sasha Levin To: Trond.Myklebust@netapp.com, bfields@fieldses.org, davem@davemloft.net Cc: davej@redhat.com, linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Sasha Levin Subject: [PATCH] SUNRPC: Prevent kernel stack corruption on long values of flush Date: Tue, 17 Jul 2012 00:01:26 +0200 Message-Id: <1342476086-21638-1-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.8.6 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The buffer size in read_flush() is too small for the longest possible values for it. This can lead to a kernel stack corruption: [ 43.047329] Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: ffffffff833e64b4 [ 43.047329] [ 43.049030] Pid: 6015, comm: trinity-child18 Tainted: G W 3.5.0-rc7-next-20120716-sasha #221 [ 43.050038] Call Trace: [ 43.050435] [] panic+0xcd/0x1f4 [ 43.050931] [] ? read_flush.isra.7+0xe4/0x100 [ 43.051602] [] __stack_chk_fail+0x16/0x20 [ 43.052206] [] read_flush.isra.7+0xe4/0x100 [ 43.052951] [] ? read_flush_pipefs+0x30/0x30 [ 43.053594] [] read_flush_procfs+0x2c/0x30 [ 43.053596] [] proc_reg_read+0x9c/0xd0 [ 43.053596] [] ? proc_reg_write+0xd0/0xd0 [ 43.053596] [] do_loop_readv_writev+0x4b/0x90 [ 43.053596] [] do_readv_writev+0xf6/0x1d0 [ 43.053596] [] vfs_readv+0x3e/0x60 [ 43.053596] [] sys_readv+0x48/0xb0 [ 43.053596] [] system_call_fastpath+0x1a/0x1f Signed-off-by: Sasha Levin --- net/sunrpc/cache.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index 2afd2a8..f86d95e 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -1409,11 +1409,11 @@ static ssize_t read_flush(struct file *file, char __user *buf, size_t count, loff_t *ppos, struct cache_detail *cd) { - char tbuf[20]; + char tbuf[22]; unsigned long p = *ppos; size_t len; - sprintf(tbuf, "%lu\n", convert_to_wallclock(cd->flush_time)); + snprintf(tbuf, sizeof(tbuf), "%lu\n", convert_to_wallclock(cd->flush_time)); len = strlen(tbuf); if (p >= len) return 0;