From unknown Mon Jun 23 07:52:20 2025 X-Loop: help-debbugs@gnu.org Subject: bug#17179: [PATCH] cp: use an invalid dev_t for an unknown device Resent-From: Dave Reisner Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 03 Apr 2014 15:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 17179 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: patch To: 17179@debbugs.gnu.org Cc: thomas@archlinux.org, Dave Reisner X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.139653959517180 (code B ref -1); Thu, 03 Apr 2014 15:40:02 +0000 Received: (at submit) by debbugs.gnu.org; 3 Apr 2014 15:39:55 +0000 Received: from localhost ([127.0.0.1]:34614 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WVjk9-0004T1-Ug for submit@debbugs.gnu.org; Thu, 03 Apr 2014 11:39:54 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57528) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WVjk6-0004Ss-9L for submit@debbugs.gnu.org; Thu, 03 Apr 2014 11:39:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WVjjy-0007xw-RB for submit@debbugs.gnu.org; Thu, 03 Apr 2014 11:39:49 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:46080) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVjjy-0007xs-O3 for submit@debbugs.gnu.org; Thu, 03 Apr 2014 11:39:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVjjs-0005JV-LK for bug-coreutils@gnu.org; Thu, 03 Apr 2014 11:39:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WVjjm-0007wY-JW for bug-coreutils@gnu.org; Thu, 03 Apr 2014 11:39:36 -0400 Received: from gerolde.archlinux.org ([66.211.214.132]:47443) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVjjm-0007wO-Fp for bug-coreutils@gnu.org; Thu, 03 Apr 2014 11:39:30 -0400 Received: from localhost (ool-4a5a30f8.dyn.optonline.net [74.90.48.248]) by gerolde.archlinux.org (Postfix) with ESMTPSA id DA054900E2; Thu, 3 Apr 2014 11:03:08 -0400 (EDT) From: Dave Reisner Date: Thu, 3 Apr 2014 11:03:14 -0400 Message-Id: <1396537394-18145-1-git-send-email-dreisner@archlinux.org> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) On the initial call to copy_internal, we must use an invalid device number. As of linux 3.14, the mount table has shifted slightly, causing the initramfs filesystem to have a devno of 0. This is valid, but confuses cp when attempting to copy only a single filesystem (cp -x). Since dev_t is defined to be an integer type, we can simply use a negative value to identify the unknown device. * src/copy.c (copy_internal): Make initial callers pass -1, compare to -1 instead of 0, and update documentation. --- Hi, This fixes a bug in Arch Linux's early userspace. We call 'cp -ax' to copy some files from the early userspace into real root. Since 3.14, this is broken and cp ignores the filesystem boundaries because it expects that 0 is an invalid device number. If you're curious about why this changed, please see my analysis on the util-linux mailing list: http://www.spinics.net/lists/util-linux-ng/msg09074.html Cheers, Dave src/copy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/copy.c b/src/copy.c index 781cc1e..472e5f7 100644 --- a/src/copy.c +++ b/src/copy.c @@ -1726,7 +1726,7 @@ should_dereference (const struct cp_options *x, bool command_line_arg) any type. NEW_DST should be true if the file DST_NAME cannot exist because its parent directory was just created; NEW_DST should be false if DST_NAME might already exist. DEVICE is the device - number of the parent directory, or 0 if the parent of this file is + number of the parent directory, or -1 if the parent of this file is not known. ANCESTORS points to a linked, null terminated list of devices and inodes of parent directories of SRC_NAME. COMMAND_LINE_ARG is true iff SRC_NAME was specified on the command line. @@ -2434,7 +2434,7 @@ copy_internal (char const *src_name, char const *dst_name, } /* Decide whether to copy the contents of the directory. */ - if (x->one_file_system && device != 0 && device != src_sb.st_dev) + if (x->one_file_system && device != -1 && device != src_sb.st_dev) { /* Here, we are crossing a file system boundary and cp's -x option is in effect: so don't copy the contents of this directory. */ @@ -2827,7 +2827,7 @@ copy (char const *src_name, char const *dst_name, top_level_dst_name = dst_name; bool first_dir_created_per_command_line_arg = false; - return copy_internal (src_name, dst_name, nonexistent_dst, 0, NULL, + return copy_internal (src_name, dst_name, nonexistent_dst, -1, NULL, options, true, &first_dir_created_per_command_line_arg, copy_into_self, rename_succeeded); -- 1.9.1 From unknown Mon Jun 23 07:52:20 2025 X-Loop: help-debbugs@gnu.org Subject: bug#17179: [PATCH] cp: use an invalid dev_t for an unknown device Resent-From: Eric Blake Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 03 Apr 2014 15:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17179 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: patch To: Dave Reisner , 17179@debbugs.gnu.org Cc: thomas@archlinux.org Received: via spool by 17179-submit@debbugs.gnu.org id=B17179.139654047418738 (code B ref 17179); Thu, 03 Apr 2014 15:55:01 +0000 Received: (at 17179) by debbugs.gnu.org; 3 Apr 2014 15:54:34 +0000 Received: from localhost ([127.0.0.1]:34633 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WVjyL-0004s8-7U for submit@debbugs.gnu.org; Thu, 03 Apr 2014 11:54:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34698) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WVjyH-0004rw-GN for 17179@debbugs.gnu.org; Thu, 03 Apr 2014 11:54:31 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s33FsPgJ004420 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 3 Apr 2014 11:54:25 -0400 Received: from [10.3.113.117] (ovpn-113-117.phx2.redhat.com [10.3.113.117]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s33FsPeQ006449; Thu, 3 Apr 2014 11:54:25 -0400 Message-ID: <533D8430.8090009@redhat.com> Date: Thu, 03 Apr 2014 09:54:24 -0600 From: Eric Blake Organization: Red Hat, Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 References: <1396537394-18145-1-git-send-email-dreisner@archlinux.org> In-Reply-To: <1396537394-18145-1-git-send-email-dreisner@archlinux.org> X-Enigmail-Version: 1.6 OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="QLn6Fu4GtWuSLUsWVc5FurnpA3VKcikn7" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Spam-Score: -5.6 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.6 (-----) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --QLn6Fu4GtWuSLUsWVc5FurnpA3VKcikn7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 04/03/2014 09:03 AM, Dave Reisner wrote: > On the initial call to copy_internal, we must use an invalid device > number. As of linux 3.14, the mount table has shifted slightly, causing= > the initramfs filesystem to have a devno of 0. This is valid, but > confuses cp when attempting to copy only a single filesystem (cp -x). > Since dev_t is defined to be an integer type, we can simply use a > negative value to identify the unknown device. dev_t is defined as an integral type, but not necessarily a signed integral type, and not necessarily a type as wide as int. Using -1 as a sentinel might be okay, but if you do, you MUST use a cast for maximum portability. > @@ -2434,7 +2434,7 @@ copy_internal (char const *src_name, char const *= dst_name, > } > =20 > /* Decide whether to copy the contents of the directory. */ > - if (x->one_file_system && device !=3D 0 && device !=3D src_sb.st= _dev) > + if (x->one_file_system && device !=3D -1 && device !=3D src_sb.s= t_dev) For example, this comparison may fail to do what you want if dev_t is uint16_t (it will ALWAYS be false, since ((uint16_t)-1) !=3D -1). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --QLn6Fu4GtWuSLUsWVc5FurnpA3VKcikn7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJTPYQwAAoJEKeha0olJ0Nq4LkIAIptEJMPRtO3vg5YM37nEpHg WfkOHTcgJU1Ip0rWTYnH70sODAxWNz7nF+bgooublLQS2wS+y2MVsn9Q8diGVSGy ywziqPqNlkcSjreJ+kPKWtPf2Idh7/UHuosNi1+o1gtU1guZBCXIw16mrKd8F8jk BQKvC4ELOch97pLzB87zkAa5eBH9b2fBV3gn91xAoA+EpAcdXu+zSlO/A9UreuRD PH0u00utRhDtvRfx0+jelXa0y3aZuesEk78Rzv49zMf6aLlFyjJ5oH23kDPhwfTi Qd39gHPzC63AVoRqqTHjfJVBGfhOubkzUL7j365k50UrtHZV2x8S0G3jJLslP+Q= =8nR8 -----END PGP SIGNATURE----- --QLn6Fu4GtWuSLUsWVc5FurnpA3VKcikn7-- From unknown Mon Jun 23 07:52:20 2025 X-Loop: help-debbugs@gnu.org Subject: bug#17179: [PATCH] cp: use an invalid dev_t for an unknown device Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 03 Apr 2014 16:39:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17179 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: patch To: Eric Blake Cc: Dave Reisner , thomas@archlinux.org, 17179@debbugs.gnu.org Received: via spool by 17179-submit@debbugs.gnu.org id=B17179.139654310423268 (code B ref 17179); Thu, 03 Apr 2014 16:39:03 +0000 Received: (at 17179) by debbugs.gnu.org; 3 Apr 2014 16:38:24 +0000 Received: from localhost ([127.0.0.1]:34658 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WVkek-00063D-OL for submit@debbugs.gnu.org; Thu, 03 Apr 2014 12:38:23 -0400 Received: from mail1.vodafone.ie ([213.233.128.43]:65335) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WVkee-00062x-11 for 17179@debbugs.gnu.org; Thu, 03 Apr 2014 12:38:17 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApQBALeNPVNtTYV7/2dsb2JhbAANQQqDQYNhwGyBNYMZAQEBAwEjBAsBRgULCw0BCgICBRYLAgIJAwIBAgFFBg0BBwEBh20NCKspdqJ8F4Epi0qBIlwHgm+BSQEDmg+FRYNniw8 Received: from unknown (HELO [192.168.1.79]) ([109.77.133.123]) by mail1.vodafone.ie with ESMTP; 03 Apr 2014 17:38:14 +0100 Message-ID: <533D8E74.1030200@draigBrady.com> Date: Thu, 03 Apr 2014 17:38:12 +0100 From: =?UTF-8?Q?P=C3=A1draig?= Brady User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 References: <1396537394-18145-1-git-send-email-dreisner@archlinux.org> <533D8430.8090009@redhat.com> In-Reply-To: <533D8430.8090009@redhat.com> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 04/03/2014 04:54 PM, Eric Blake wrote: > On 04/03/2014 09:03 AM, Dave Reisner wrote: >> On the initial call to copy_internal, we must use an invalid device >> number. As of linux 3.14, the mount table has shifted slightly, causing >> the initramfs filesystem to have a devno of 0. This is valid, but >> confuses cp when attempting to copy only a single filesystem (cp -x). >> Since dev_t is defined to be an integer type, we can simply use a >> negative value to identify the unknown device. This kernel change seems like it might break lots of stuff. For example I did a simplistic search for "st_dev == 0" and noticed also: http://cgit.freedesktop.org/systemd/systemd/plain/src/readahead/readahead-common.c Has the question been broached with the kernel folks about compat? > dev_t is defined as an integral type, but not necessarily a signed > integral type, and not necessarily a type as wide as int. Using -1 as a > sentinel might be okay, but if you do, you MUST use a cast for maximum > portability. > >> @@ -2434,7 +2434,7 @@ copy_internal (char const *src_name, char const *dst_name, >> } >> >> /* Decide whether to copy the contents of the directory. */ >> - if (x->one_file_system && device != 0 && device != src_sb.st_dev) >> + if (x->one_file_system && device != -1 && device != src_sb.st_dev) > > For example, this comparison may fail to do what you want if dev_t is > uint16_t (it will ALWAYS be false, since ((uint16_t)-1) != -1). Right, so: >> - if (x->one_file_system && device != 0 && device != src_sb.st_dev) >> + if (x->one_file_system && device != (dev_t) -1 && device != src_sb.st_dev) Given the age of these assumptions, I'd be as much worried about a clash with (dev_t)-1 as 0 TBH? Pádraig From unknown Mon Jun 23 07:52:20 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.503 (Entity 5.503) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Dave Reisner Subject: bug#17179: closed (Re: bug#17179: [PATCH] cp: use an invalid dev_t for an unknown device) Message-ID: References: <533D915E.9020500@cs.ucla.edu> <1396537394-18145-1-git-send-email-dreisner@archlinux.org> X-Gnu-PR-Message: they-closed 17179 X-Gnu-PR-Package: coreutils X-Gnu-PR-Keywords: patch Reply-To: 17179@debbugs.gnu.org Date: Thu, 03 Apr 2014 16:51:04 +0000 Content-Type: multipart/mixed; boundary="----------=_1396543864-24595-1" This is a multi-part message in MIME format... ------------=_1396543864-24595-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #17179: [PATCH] cp: use an invalid dev_t for an unknown device which was filed against the coreutils package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 17179@debbugs.gnu.org. --=20 17179: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D17179 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1396543864-24595-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 17179-done) by debbugs.gnu.org; 3 Apr 2014 16:50:48 +0000 Received: from localhost ([127.0.0.1]:34676 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WVkqj-0006OC-0t for submit@debbugs.gnu.org; Thu, 03 Apr 2014 12:50:47 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:48985) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WVkqe-0006Nz-4y for 17179-done@debbugs.gnu.org; Thu, 03 Apr 2014 12:50:41 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id A3A5B39E8018; Thu, 3 Apr 2014 09:50:39 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ppxsEKfmkXsU; Thu, 3 Apr 2014 09:50:38 -0700 (PDT) Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 9706B39E8012; Thu, 3 Apr 2014 09:50:38 -0700 (PDT) Message-ID: <533D915E.9020500@cs.ucla.edu> Date: Thu, 03 Apr 2014 09:50:38 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= , Eric Blake Subject: Re: bug#17179: [PATCH] cp: use an invalid dev_t for an unknown device References: <1396537394-18145-1-git-send-email-dreisner@archlinux.org> <533D8430.8090009@redhat.com> <533D8E74.1030200@draigBrady.com> In-Reply-To: <533D8E74.1030200@draigBrady.com> Content-Type: multipart/mixed; boundary="------------070200000509060904050204" X-Spam-Score: -2.9 (--) X-Debbugs-Envelope-To: 17179-done Cc: Dave Reisner , thomas@archlinux.org, 17179-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.9 (--) This is a multi-part message in MIME format. --------------070200000509060904050204 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 04/03/2014 09:38 AM, Pádraig Brady wrote: > I'd be as much worried about > a clash with (dev_t)-1 as 0 TBH? Absolutely. I installed the attached patch, which should work regardless of what dev_t values are found in the file system. This fixes just this particular bug, though; I wouldn't be surprised if there are others (and haven't looked for them). --------------070200000509060904050204 Content-Type: text/x-patch; name="0001-cp-don-t-reserve-a-device-number.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-cp-don-t-reserve-a-device-number.patch" >From ee96d171ddf584f9d8faad1830aa1daf89de2d55 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 3 Apr 2014 09:48:22 -0700 Subject: [PATCH] cp: don't reserve a device number * src/copy.c (copy_internal): Replace dev_t arg DEVICE with struct stat pointer arg PARENT. All callers changed. This removes an unwarranted assumption that dev_t values of 0 cannot occur in file systems. See: http://bugs.gnu.org/17179 --- src/copy.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/copy.c b/src/copy.c index 781cc1e..d471a77 100644 --- a/src/copy.c +++ b/src/copy.c @@ -117,7 +117,7 @@ struct dir_list #define DEST_INFO_INITIAL_CAPACITY 61 static bool copy_internal (char const *src_name, char const *dst_name, - bool new_dst, dev_t device, + bool new_dst, struct stat const *parent, struct dir_list *ancestors, const struct cp_options *x, bool command_line_arg, @@ -621,7 +621,7 @@ copy_dir (char const *src_name_in, char const *dst_name_in, bool new_dst, char *dst_name = file_name_concat (dst_name_in, namep, NULL); bool first_dir_created = *first_dir_created_per_command_line_arg; - ok &= copy_internal (src_name, dst_name, new_dst, src_sb->st_dev, + ok &= copy_internal (src_name, dst_name, new_dst, src_sb, ancestors, &non_command_line_options, false, &first_dir_created, &local_copy_into_self, NULL); @@ -1725,9 +1725,8 @@ should_dereference (const struct cp_options *x, bool command_line_arg) /* Copy the file SRC_NAME to the file DST_NAME. The files may be of any type. NEW_DST should be true if the file DST_NAME cannot exist because its parent directory was just created; NEW_DST should - be false if DST_NAME might already exist. DEVICE is the device - number of the parent directory, or 0 if the parent of this file is - not known. ANCESTORS points to a linked, null terminated list of + be false if DST_NAME might already exist. A nonnull PARENT describes the + parent directory. ANCESTORS points to a linked, null terminated list of devices and inodes of parent directories of SRC_NAME. COMMAND_LINE_ARG is true iff SRC_NAME was specified on the command line. FIRST_DIR_CREATED_PER_COMMAND_LINE_ARG is both input and output. @@ -1737,7 +1736,7 @@ should_dereference (const struct cp_options *x, bool command_line_arg) static bool copy_internal (char const *src_name, char const *dst_name, bool new_dst, - dev_t device, + struct stat const *parent, struct dir_list *ancestors, const struct cp_options *x, bool command_line_arg, @@ -2434,7 +2433,7 @@ copy_internal (char const *src_name, char const *dst_name, } /* Decide whether to copy the contents of the directory. */ - if (x->one_file_system && device != 0 && device != src_sb.st_dev) + if (x->one_file_system && parent && parent->st_dev != src_sb.st_dev) { /* Here, we are crossing a file system boundary and cp's -x option is in effect: so don't copy the contents of this directory. */ @@ -2827,7 +2826,7 @@ copy (char const *src_name, char const *dst_name, top_level_dst_name = dst_name; bool first_dir_created_per_command_line_arg = false; - return copy_internal (src_name, dst_name, nonexistent_dst, 0, NULL, + return copy_internal (src_name, dst_name, nonexistent_dst, NULL, NULL, options, true, &first_dir_created_per_command_line_arg, copy_into_self, rename_succeeded); -- 1.9.0 --------------070200000509060904050204-- ------------=_1396543864-24595-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 3 Apr 2014 15:39:55 +0000 Received: from localhost ([127.0.0.1]:34614 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WVjk9-0004T1-Ug for submit@debbugs.gnu.org; Thu, 03 Apr 2014 11:39:54 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57528) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WVjk6-0004Ss-9L for submit@debbugs.gnu.org; Thu, 03 Apr 2014 11:39:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WVjjy-0007xw-RB for submit@debbugs.gnu.org; Thu, 03 Apr 2014 11:39:49 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:46080) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVjjy-0007xs-O3 for submit@debbugs.gnu.org; Thu, 03 Apr 2014 11:39:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVjjs-0005JV-LK for bug-coreutils@gnu.org; Thu, 03 Apr 2014 11:39:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WVjjm-0007wY-JW for bug-coreutils@gnu.org; Thu, 03 Apr 2014 11:39:36 -0400 Received: from gerolde.archlinux.org ([66.211.214.132]:47443) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVjjm-0007wO-Fp for bug-coreutils@gnu.org; Thu, 03 Apr 2014 11:39:30 -0400 Received: from localhost (ool-4a5a30f8.dyn.optonline.net [74.90.48.248]) by gerolde.archlinux.org (Postfix) with ESMTPSA id DA054900E2; Thu, 3 Apr 2014 11:03:08 -0400 (EDT) From: Dave Reisner To: bug-coreutils@gnu.org Subject: [PATCH] cp: use an invalid dev_t for an unknown device Date: Thu, 3 Apr 2014 11:03:14 -0400 Message-Id: <1396537394-18145-1-git-send-email-dreisner@archlinux.org> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit Cc: thomas@archlinux.org, Dave Reisner X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) On the initial call to copy_internal, we must use an invalid device number. As of linux 3.14, the mount table has shifted slightly, causing the initramfs filesystem to have a devno of 0. This is valid, but confuses cp when attempting to copy only a single filesystem (cp -x). Since dev_t is defined to be an integer type, we can simply use a negative value to identify the unknown device. * src/copy.c (copy_internal): Make initial callers pass -1, compare to -1 instead of 0, and update documentation. --- Hi, This fixes a bug in Arch Linux's early userspace. We call 'cp -ax' to copy some files from the early userspace into real root. Since 3.14, this is broken and cp ignores the filesystem boundaries because it expects that 0 is an invalid device number. If you're curious about why this changed, please see my analysis on the util-linux mailing list: http://www.spinics.net/lists/util-linux-ng/msg09074.html Cheers, Dave src/copy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/copy.c b/src/copy.c index 781cc1e..472e5f7 100644 --- a/src/copy.c +++ b/src/copy.c @@ -1726,7 +1726,7 @@ should_dereference (const struct cp_options *x, bool command_line_arg) any type. NEW_DST should be true if the file DST_NAME cannot exist because its parent directory was just created; NEW_DST should be false if DST_NAME might already exist. DEVICE is the device - number of the parent directory, or 0 if the parent of this file is + number of the parent directory, or -1 if the parent of this file is not known. ANCESTORS points to a linked, null terminated list of devices and inodes of parent directories of SRC_NAME. COMMAND_LINE_ARG is true iff SRC_NAME was specified on the command line. @@ -2434,7 +2434,7 @@ copy_internal (char const *src_name, char const *dst_name, } /* Decide whether to copy the contents of the directory. */ - if (x->one_file_system && device != 0 && device != src_sb.st_dev) + if (x->one_file_system && device != -1 && device != src_sb.st_dev) { /* Here, we are crossing a file system boundary and cp's -x option is in effect: so don't copy the contents of this directory. */ @@ -2827,7 +2827,7 @@ copy (char const *src_name, char const *dst_name, top_level_dst_name = dst_name; bool first_dir_created_per_command_line_arg = false; - return copy_internal (src_name, dst_name, nonexistent_dst, 0, NULL, + return copy_internal (src_name, dst_name, nonexistent_dst, -1, NULL, options, true, &first_dir_created_per_command_line_arg, copy_into_self, rename_succeeded); -- 1.9.1 ------------=_1396543864-24595-1--