From patchwork Wed May 21 16:38:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 4217791 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0B20A9F32A for ; Wed, 21 May 2014 15:38:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C648A20131 for ; Wed, 21 May 2014 15:38:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 01CFE20114 for ; Wed, 21 May 2014 15:38:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752098AbaEUPi1 (ORCPT ); Wed, 21 May 2014 11:38:27 -0400 Received: from mail-we0-f174.google.com ([74.125.82.174]:39464 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751781AbaEUPiZ (ORCPT ); Wed, 21 May 2014 11:38:25 -0400 Received: by mail-we0-f174.google.com with SMTP id k48so2194438wev.5 for ; Wed, 21 May 2014 08:38:23 -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:in-reply-to:references; bh=kIUU3yH0A0lFs+3J2BlZN1WpqN6n0AMPdAm//GJj0HY=; b=ORD4Y4K+ib/HAE2+j/83fbEKWFSNtCawjAGMJ43Kjd5brDEN3dpRekUhH9jG4mOT67 5JFnbprMV+ryDGQY+8fe8Pl/eIyGV6+VZzO/d9qN5cSrFGFoC3eeknHGvSqi/oE6aPdk mfhA0HoVQQxHzAuIxJVdEO7dGAFqajtsSvkZBHLZpBPjjTpB5H6JJRuRTUxxikRO3QrI Gv9svUSUBx7iIltsRECDSQlJts7FRytzQG6kchBjULNiG1BVVcRV2IyMYRsAhR1NnaDd Si07Da73hmzOgCYaXkn0fMiHXnFEgFS1UJx2cAKRbrgkHjRuScvF1rxYGATY3omL2tBM kwdw== X-Received: by 10.194.6.106 with SMTP id z10mr43729803wjz.1.1400686703631; Wed, 21 May 2014 08:38:23 -0700 (PDT) Received: from debian-vm3.lan (bl10-252-12.dsl.telepac.pt. [85.243.252.12]) by mx.google.com with ESMTPSA id dr6sm2882661wid.6.2014.05.21.08.38.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 May 2014 08:38:22 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: clm@fb.com, Filipe David Borba Manana , Marc Merlin Subject: [PATCH v2] Btrfs: send, fix corrupted path strings for long paths Date: Wed, 21 May 2014 17:38:13 +0100 Message-Id: <1400690293-14506-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1400689419-13446-1-git-send-email-fdmanana@gmail.com> References: <1400689419-13446-1-git-send-email-fdmanana@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If a path has more than 230 characters, we allocate a new buffer to use for the path, but we were forgotting to copy the contents of the previous buffer into the new one, which has random content from the kmalloc call. Test: mkfs.btrfs -f /dev/sdd mount /dev/sdd /mnt TEST_PATH="/mnt/fdmanana/.config/google-chrome-mysetup/Default/Pepper_Data/Shockwave_Flash/WritableRoot/#SharedObjects/JSHJ4ZKN/s.wsj.net/[[IMPORT]]/players.edgesuite.net/flash/plugins/osmf/advanced-streaming-plugin/v2.7/osmf1.6/Ak#" mkdir -p $TEST_PATH echo "hello world" > $TEST_PATH/amaiAdvancedStreamingPlugin.txt btrfs subvolume snapshot -r /mnt /mnt/mysnap1 btrfs send /mnt/mysnap1 -f /tmp/1.snap A test for xfstests follows. Signed-off-by: Filipe David Borba Manana Cc: Marc Merlin Tested-by: Marc MERLIN --- V2: Fix change title, "paths" to "path". fs/btrfs/send.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index f6bbc1e..70c5e8c 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -368,10 +368,13 @@ static int fs_path_ensure_buf(struct fs_path *p, int len) /* * First time the inline_buf does not suffice */ - if (p->buf == p->inline_buf) + if (p->buf == p->inline_buf) { tmp_buf = kmalloc(len, GFP_NOFS); - else + if (tmp_buf) + memcpy(tmp_buf, p->buf, old_buf_len); + } else { tmp_buf = krealloc(p->buf, len, GFP_NOFS); + } if (!tmp_buf) return -ENOMEM; p->buf = tmp_buf;