[Bug 2067138] [NEW] Dir::Cache=/dev/null chmods /dev/null

Julian Andres Klode 2067138 at bugs.launchpad.net
Sat May 25 08:56:39 UTC 2024


Public bug reported:

[Impact]
If you set Dir::Cache or Dir::Cache::pkgcache to /dev/null, /dev/null is chmodded as we chmod the cache file to 666. This is a semi-common pattern to not use a cache, and breaks user scripts.

[Test plan]
1. autopkgtests run the large integration test suite 
2. run manually
   apt-cache gencaches -o Dir::Cache::pkgcache=/dev/null
   apt-cache gencaches -o Dir::Cache::srcpkgcache=/dev/null
   apt-cache gencaches -o Dir::Cache=/dev/null
   and observe that /dev/null is still correct.

[Where problems could occur]
We have eliminated writing the cache to /dev/null entirely:

--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -1637,6 +1637,10 @@ static DynamicMMap* CreateDynamicMMap(FileFd * const CacheF, unsigned long Flags
 static bool writeBackMMapToFile(pkgCacheGenerator * const Gen, DynamicMMap * const Map,
       std::string const &FileName)
 {
+   // Do not write the file back to /dev/null or try to change its mode...
+   if (FileName == "/dev/null")
+      return true;

It's possible we may introduce issues later because something in there
does fancy bits and the cache in memory becomes invalid, but so far I
only saw that we calculate the hash in there, but we set dirty
afterwards and don't actually use the cache hash if we don't load from
disk so I think in reality this is not a problem, at least now. Just
gotta be careful to not stuff anything other than writing in there.

** Affects: apt (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to apt in Ubuntu.
https://bugs.launchpad.net/bugs/2067138

Title:
  Dir::Cache=/dev/null chmods /dev/null

Status in apt package in Ubuntu:
  New

Bug description:
  [Impact]
  If you set Dir::Cache or Dir::Cache::pkgcache to /dev/null, /dev/null is chmodded as we chmod the cache file to 666. This is a semi-common pattern to not use a cache, and breaks user scripts.

  [Test plan]
  1. autopkgtests run the large integration test suite 
  2. run manually
     apt-cache gencaches -o Dir::Cache::pkgcache=/dev/null
     apt-cache gencaches -o Dir::Cache::srcpkgcache=/dev/null
     apt-cache gencaches -o Dir::Cache=/dev/null
     and observe that /dev/null is still correct.

  [Where problems could occur]
  We have eliminated writing the cache to /dev/null entirely:

  --- a/apt-pkg/pkgcachegen.cc
  +++ b/apt-pkg/pkgcachegen.cc
  @@ -1637,6 +1637,10 @@ static DynamicMMap* CreateDynamicMMap(FileFd * const CacheF, unsigned long Flags
   static bool writeBackMMapToFile(pkgCacheGenerator * const Gen, DynamicMMap * const Map,
         std::string const &FileName)
   {
  +   // Do not write the file back to /dev/null or try to change its mode...
  +   if (FileName == "/dev/null")
  +      return true;

  It's possible we may introduce issues later because something in there
  does fancy bits and the cache in memory becomes invalid, but so far I
  only saw that we calculate the hash in there, but we set dirty
  afterwards and don't actually use the cache hash if we don't load from
  disk so I think in reality this is not a problem, at least now. Just
  gotta be careful to not stuff anything other than writing in there.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/apt/+bug/2067138/+subscriptions




More information about the foundations-bugs mailing list