Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: kernel_include.py: fix an issue when O= is used

As reported by Stephen, building docs with O= is now
broken. Fix it by ensuring that it will seek files under
Kernel source tree.

The original logic was defined to accept including files
under Documentation/output. The new logic doesn't need it
anymore for media, but it might still be useful to preserve
the previous behavior. So, I ended preserving it.

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Closes: https://lore.kernel.org/all/20250901142639.4de35a11@canb.auug.org.au/
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/da91980ce42f31730dc982920167b2757b9d2769.1756732363.git.mchehab+huawei@kernel.org

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
8dbb1779 d90e7b56

+39 -5
+39 -5
Documentation/sphinx/kernel_include.py
··· 314 314 def run(self): 315 315 """Include a file as part of the content of this reST file.""" 316 316 env = self.state.document.settings.env 317 - path = os.path.realpath(os.path.expandvars(self.arguments[0])) 318 317 319 - # to get a bit security back, prohibit /etc: 320 - if path.startswith(os.sep + "etc"): 321 - raise self.severe('Problems with "%s" directive, prohibited path: %s' % 322 - (self.name, path)) 318 + # 319 + # The include logic accepts only patches relative to: 320 + # - Kernel source tree 321 + # - Documentation output directory 322 + # 323 + # The logic does check it to prevent directory traverse 324 + # 325 + 326 + srctree = os.path.abspath(os.environ["srctree"]) 327 + 328 + path = os.path.expandvars(self.arguments[0]) 329 + src_path = os.path.join(srctree, path) 330 + 331 + if os.path.isfile(src_path): 332 + base = srctree 333 + path = src_path 334 + elif os.path.exists(arg): 335 + # Allow patches from output dir 336 + base = os.getcwd() 337 + path = os.path.abspath(path) 338 + else: 339 + raise self.warning(f'File "%s" doesn\'t exist', path) 340 + 341 + abs_base = os.path.abspath(base) 342 + abs_full_path = os.path.abspath(os.path.join(base, path)) 343 + 344 + try: 345 + if os.path.commonpath([abs_full_path, abs_base]) != abs_base: 346 + raise self.severe('Problems with "%s" directive, prohibited path: %s' % 347 + (self.name, path)) 348 + except ValueError: 349 + # Paths don't have the same drive (Windows) or other incompatibility 350 + raise self.severe('Problems with "%s" directive, invalid path: %s' % 351 + (self.name, path)) 323 352 324 353 self.arguments[0] = path 354 + 355 + # 356 + # Add path location to Sphinx dependencies to ensure proper cache 357 + # invalidation check. 358 + # 325 359 326 360 env.note_dependency(os.path.abspath(path)) 327 361