RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1510002 - Ensure that the command input (stdin) eating behaviour of Default log_input is documented
Summary: Ensure that the command input (stdin) eating behaviour of Default log_input i...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: sudo
Version: 7.4
Hardware: x86_64
OS: Linux
medium
high
Target Milestone: rc
: ---
Assignee: Radovan Sroka
QA Contact: Dalibor Pospíšil
URL:
Whiteboard:
Depends On: 1547974
Blocks: 1477664
TreeView+ depends on / blocked
 
Reported: 2017-11-06 14:32 UTC by Dalibor Pospíšil
Modified: 2021-12-10 15:23 UTC (History)
5 users (show)

Fixed In Version: sudo-1.8.23-1.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-10-30 11:09:01 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 1454571 0 high CLOSED Sudo, with I/O Logging log_output option enabled, truncate output in case of cycle over standard input 2021-12-10 15:03:58 UTC
Red Hat Product Errata RHEA-2018:3199 0 None None None 2018-10-30 11:09:46 UTC

Internal Links: 1454571

Description Dalibor Pospíšil 2017-11-06 14:32:56 UTC
Description of problem:

There's an issue with sudo, that is truncating output in stdout file descriptor upon log_input (io logging) option usage.

Version-Release number of selected component (if applicable):

Affected and tested versions:
sudo-1.8.19p2-12.el7
sudo-1.8.19p2-11.el7

How reproducible:
Always

Steps to Reproduce:

Just run this script (also attacched):

#!/bin/bash
printf "usqpsinfra1\nusqpsinfra2\n" | while read node; do sudo echo $node; done

Actual results:
only usqpsinfra1 is outputted:

$ bash -x test
+ read node
+ printf 'usqpsinfra1\nusqpsinfra2\n'
+ sudo echo usqpsinfra1
usqpsinfra1
+ read node
$

Expected results:
$ bash -x test
+ read node
+ printf 'usqpsinfra1\nusqpsinfra2\n'
+ sudo echo usqpsinfra1
usqpsinfra1
+ read node
+ sudo echo usqpsinfra2
usqpsinfra2
+ read node
$

Comment 2 Radovan Sroka 2018-06-20 10:53:20 UTC
Hi guys,

after some investigation we can say that this is not a bug.

The problem is that "sudo" and "read" stdin is inherited from while. "read" reads 1st line from stdin and then sudo is called and io-logging plugin consumes the rest of the stdin. stdin content is not supposed to be for "sudo" but sudo has no idea whether stdin is shared or not.

It is much better to use some of the following work arounds to avoid confusion.

printf "a\nb\nc\n" | sudo bash -c 'while read a; do echo $a; done'
printf "a\nb\nc\n" | while read a; do sudo echo $a 0<&- ; done
printf "a\nb\nc\n" | while read a; do : | sudo echo $a ; done

It is also documented in manual (man sudoers).

"Anything sent to the standard input will be consumed, regardless of whether or not the command run via sudo is actually reading the standard input. This may have unexpected results when using sudo in a shell script that expects to process the standard input." ---> log_input documentation

https://www.sudo.ws/man/1.8.22/sudoers.man.html

Comment 3 Dalibor Pospíšil 2018-06-20 18:56:37 UTC
So do I understand correctly, that sudo eats all the input up, except for the first line, before the read gets in line?

Comment 4 Radovan Sroka 2018-06-21 07:53:51 UTC
(In reply to Dalibor Pospíšil from comment #3)
> So do I understand correctly, that sudo eats all the input up, except for
> the first line, before the read gets in line?

It should be like that:

printf "usqpsinfra1\nusqpsinfra2\n" | while read node; do sudo echo $node; done

$ bash -x test
+ read node    <--- read was forked from while
+ printf 'usqpsinfra1\nusqpsinfra2\n' <--- send data to while's stdin
+                         <--- read eats the first line
+ sudo echo usqpsinfra1   <--- sudo was forked from while with first line as argument and it eats the rest of stdin
usqpsinfra1    <--- stdout of sudo
+ read node    <--- read has no input so loop is over
$

Comment 9 errata-xmlrpc 2018-10-30 11:09:01 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2018:3199


Note You need to log in before you can comment on or make changes to this bug.