From unknown Thu Jun 19 13:54:05 2025 X-Loop: help-debbugs@gnu.org Subject: bug#52048: Bug in shred -u Resent-From: David McLaughlin Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Tue, 23 Nov 2021 00:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 52048 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 52048@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.1637628456428 (code B ref -1); Tue, 23 Nov 2021 00:48:02 +0000 Received: (at submit) by debbugs.gnu.org; 23 Nov 2021 00:47:36 +0000 Received: from localhost ([127.0.0.1]:49437 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mpJyA-00006a-0H for submit@debbugs.gnu.org; Mon, 22 Nov 2021 19:47:36 -0500 Received: from lists.gnu.org ([209.51.188.17]:41930) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mpHgE-0004Td-3C for submit@debbugs.gnu.org; Mon, 22 Nov 2021 17:20:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpHgD-0001yA-Om for bug-coreutils@gnu.org; Mon, 22 Nov 2021 17:20:53 -0500 Received: from [2a00:1450:4864:20::531] (port=40583 helo=mail-ed1-x531.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mpHgA-0002yK-Dl for bug-coreutils@gnu.org; Mon, 22 Nov 2021 17:20:53 -0500 Received: by mail-ed1-x531.google.com with SMTP id r25so46438959edq.7 for ; Mon, 22 Nov 2021 14:20:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=theredx.com; s=google2; h=mime-version:from:date:message-id:subject:to; bh=I1vKrbpZCuD+ab+CTchl1YPBqgOE04kFIe7XTJQ9IA8=; b=cLZRje8AtpQR0stYROxAtto5bEaMItE0HGDaS+xyGvYgtc1Va37/1Yy8GVHntN9lkd 2i0+zQM4pz2V+/HmC9f3O5s1Pa8V7kZZ5/gFWqk1Q1AZ2TjzGmKnYY5aXWltwiV5/x0D 6nM22ftAMESGkNOmkIsdRY8TBR6aAHbpv6dmYlG9Tn3F6UkJox6BakANnsrle8IiYVgG gDjVddrmMDvR6rZsz3cab/vZiy6jrygotTBLUA6S0m9EJu79QXmFsDpOEvUGmQjh2IJp BySm6xMYJ9vGIL5JEFb6sai0aAt4KvfPmUfZqTV7bGYVm18AiUr04O+Xbv8EISN17dxn Bziw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=I1vKrbpZCuD+ab+CTchl1YPBqgOE04kFIe7XTJQ9IA8=; b=ZgI8NZk8P3xFLxIi+m0/v1L9fVg+ySWtIRzI8NhglU2T+N4LO0pI7nqXpzmBBcyRtt Xd7yWtaoeJFeGryfQWDoiw+GuRirjPGyeWr7k1qvpds0+cu6ZUy5CzarHYtF+9bmeDu3 ard1PbLaAXueoXNFg3wfVqUxOFyiExK53T7HUxdTSW6qlTgzij1vfuvl0JU+it6o9O0z 62z4GK2vLcuB99QWLtysxLsCLZhPnc7kgMvKczEalJOLCRjKKTJ6Ye6Y89rc7wOtR4s3 XDOShEUy/YsFpB5d7ItlqH96iyghATuPvp6ZEPlLkeJEe4KB3W38c8ieF0Iwx1IDkwHP JYCA== X-Gm-Message-State: AOAM5337jU6p/s6a9nszCChy2/zTgfuew8Je7+HtN4QbTTFoXc/R23Rv k/2ssnH5dPHlNECHoKkAlIcuI5oP8OgvGGAetB6g4LQ6t99FWg== X-Google-Smtp-Source: ABdhPJzDVrJ3V1wLSj5mYLzRDOaCdQHNyUSoU08L/boFHsWS+PDuAOPuxus9AEDfi0oUMLgYDu2dSrZ+P74Q5OTcZAI= X-Received: by 2002:a17:907:7f9e:: with SMTP id qk30mr955497ejc.238.1637619647616; Mon, 22 Nov 2021 14:20:47 -0800 (PST) MIME-Version: 1.0 From: David McLaughlin Date: Mon, 22 Nov 2021 15:20:11 -0700 Message-ID: Content-Type: multipart/alternative; boundary="0000000000005fb88305d16809c7" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::531 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::531; envelope-from=david.mclaughlin@theredx.com; helo=mail-ed1-x531.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Mailman-Approved-At: Mon, 22 Nov 2021 19:47:33 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 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.3 (--) --0000000000005fb88305d16809c7 Content-Type: text/plain; charset="UTF-8" Hello, It seems that shred utilizes a pattern of renaming and then unlinking. However, I don't see the use of a lock for this pattern and so there is a race condition and the shred command can fail. This test case is timing sensitive, and therefore doesn't happen every time. But it happens frequently. I am trying to write robust code that depends on shred and I find this issue is problematic. Test case: $ touch a b c && for file in a b c; do shred -u -n 1 $file & done && wait [1] 28262 [2] 28263 [3] 28264 shred: c: failed to remove: No such file or directory [1] Done shred -u -n 1 "$file" [2]- Done shred -u -n 1 "$file" [3]+ Exit 1 shred -u -n 1 "$file" Other information: $ shred --version shred (GNU coreutils) 8.21 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Colin Plumb. $ cat /etc/os-release NAME="Ubuntu" VERSION="14.04.6 LTS, Trusty Tahr" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 14.04.6 LTS" VERSION_ID="14.04" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" $ bash --version GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. --0000000000005fb88305d16809c7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,

It seems that shred u= tilizes a pattern of renaming and then unlinking.
However, I don&= #39;t see the use of a lock for this pattern and so there is a race conditi= on and the shred command can fail. This test case is timing sensitive, and = therefore doesn't happen every time. But it happens frequently. I am tr= ying to write robust code that depends on shred and I find this issue is pr= oblematic.

Test case:
$ touch a b c = && for file in a b c; do shred -u -n 1 $file & done && = wait
[1] 28262
[2] 28263
[3] 28264
shred: c: failed to remove: = No such file or directory
[1] =C2=A0 Done =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0shred -u -n 1 "$file"[2]- =C2=A0Done =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0shred -u -n 1 "$file"
[3]+ =C2=A0Exit 1 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0shred -u -n 1 "= $file"


Other information:
$ shred --version
shred (GNU coreutils) 8.21
Copyright (C) 2013= Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or lat= er <http://gnu.org/licenses= /gpl.html>.
This is free software: you are free to change and red= istribute it.
There is NO WARRANTY, to the extent permitted by law.
<= br>Written by Colin Plumb.

$ cat /etc/os-release <= br>NAME=3D"Ubuntu"
VERSION=3D"14.04.6 LTS, Trusty Tahr&qu= ot;
ID=3Dubuntu
ID_LIKE=3Ddebian
PRETTY_NAME=3D"Ubuntu 14.04.= 6 LTS"
VERSION_ID=3D"14.04"
HOME_URL=3D"http://www.ubuntu.com/"
SUPPORT_URL= =3D"http://help.ubuntu.com/&qu= ot;
BUG_REPORT_URL=3D"http://bugs.launchpad.net/ubuntu/"

$ bas= h --version
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU G= PL version 3 or later <http= ://gnu.org/licenses/gpl.html>

This is free software; you are = free to change and redistribute it.
There is NO WARRANTY, to the extent = permitted by law.
--0000000000005fb88305d16809c7-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 27 20:51:27 2022 Received: (at control) by debbugs.gnu.org; 28 Jan 2022 01:51:27 +0000 Received: from localhost ([127.0.0.1]:57020 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nDGQB-0005hG-JL for submit@debbugs.gnu.org; Thu, 27 Jan 2022 20:51:27 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:58418) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nDGQ8-0005gz-PM for control@debbugs.gnu.org; Thu, 27 Jan 2022 20:51:26 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 67AFF160126 for ; Thu, 27 Jan 2022 17:51:18 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 7K314hraWD_J for ; Thu, 27 Jan 2022 17:51:17 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id C7B14160133 for ; Thu, 27 Jan 2022 17:51:17 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id nT2aEvYKyzsD for ; Thu, 27 Jan 2022 17:51:17 -0800 (PST) Received: from [192.168.1.9] (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id A00B2160126 for ; Thu, 27 Jan 2022 17:51:17 -0800 (PST) Message-ID: Date: Thu, 27 Jan 2022 17:51:17 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-US To: control@debbugs.gnu.org From: Paul Eggert Subject: 52048 and 52049 are duplicates Organization: UCLA Computer Science Department Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 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: -3.3 (---) unarchive 52049 tags 52049 notabug tags 52048 notabug close 52048 merge 52048 52049