X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Message-ID: <4D88DF18.8050401@redhat.com> Date: Tue, 22 Mar 2011 11:40:40 -0600 From: Eric Blake User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.9 MIME-Version: 1.0 To: cygwin Subject: O_ACCMODE is wrong OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig8FE6870F89E2C53BA56C97DA" X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com --------------enig8FE6870F89E2C53BA56C97DA Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable First, some background: POSIX 2008 introduced O_SEARCH and O_EXEC, and states that they may (but not must) share the same bit, since the former is for directories and the latter for non-directories (cygwin shares these as 0x400000). POSIX states that implementations need not reject O_EXEC|O_RDONLY (to cater to systems like cygwin where O_RDONLY is 0), but that they may on systems where it is detectable (such as on Hurd where O_RDONLY is 1). It also requires that an application must provide exactly one of the five modes O_RDONLY, O_WRONLY, O_RDWR, O_SEARCH, or O_EXEC), and therefore an implementation should reject a bit-wise or that tries to mix those modes). However, in introducing the new values, POSIX also required that O_ACCMODE be updated to cover those new modes. Now for the bugs: cygwin's defines O_ACCMODE as 3 instead of 0x400003, and as a result, a regular file opened for O_EXEC (or a directory for O_SEARCH) but probed via fcntl(F_GETFL)&O_ACCMODE will mistakenly show up as O_RDONLY instead of the proper mode. Meanwhile, open(O_EXEC|O_WRONLY) isn't rejected as an invalid mode. However, just changing O_ACCMODE to the correct value may expose other latent bugs in the rest of cygwin1.dll, since it looks like there are existing places where cygwin is making assumptions that rely on O_ACCMODE being exactly 3, so it would require a careful audit to fix it all. --=20 Eric Blake eblake AT redhat DOT com +1-801-349-2682 Libvirt virtualization library http://libvirt.org --------------enig8FE6870F89E2C53BA56C97DA 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.4.11 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJNiN8YAAoJEKeha0olJ0NqiGoH/A2sV9gFzQkD/IdUiGYa5p9H qcF5GTRb841fcXuQXpSgamn6a/6rYPdsRPdJ4QnI+iNl16QHv4mtoG4KEJUYXzPW GexK6xsayafRvbEyMGJYqD145+OXdnpzetg8wC32774JEpIs0Pxw9otJvrtwNPVS H3eh9PQpwHt46VMiLpPp1XcU8lboHdXMQRPmUzob6FEQx/ggtMH/Ceyl4+vkUCzh gDqnJMwyZgF8Z1iip4a2Ll1ZS64CMozgaA8HnbB3xNj9kE5FB/0nhh2KAVTUXO/N zzG9pzm7mnfeAoHuX0knf9VyIJHJG7aa6S8dZDSAbuZOp8VUGIceuJ9VucLyZ8Y= =DrxE -----END PGP SIGNATURE----- --------------enig8FE6870F89E2C53BA56C97DA--