linux-uek icon indicating copy to clipboard operation
linux-uek copied to clipboard

MADV_DOEXEC and MADV_DONTEXEC should be redefined within a separate numerical range

Open cnqpzhang opened this issue 1 year ago • 2 comments
trafficstars

Description:

MADV_DOEXEC and MADV_DONTEXEC should be redefined within a separate numerical range otherwise break binary compatibility with mainline kernels.

Diagnostic Info:

Kernel v5.4 build from uek6/u3 has a commit https://github.com/oracle/linux-uek/commit/a91ae4fa327d8957e2f806420b8b835269b85bd4, which had two madvise mode numbers defined as below:

#define MADV_DOEXEC	22		/* do inherit across exec */
#define MADV_DONTEXEC	23		/* don't inherit across exec */

In comparison, Linux mainline v5.4 does not have such definitions, the top number was 21, see v5.4 219d54332

Moving forward, Linux mainline started to use number 22 and 23, at its 5.14-rc1 timeframe, see https://github.com/torvalds/linux/commit/4ca9b3859dac14bbef0c27d00667bb5b10917adb.

#define MADV_POPULATE_READ	22	/* populate (prefault) page tables readable */
#define MADV_POPULATE_WRITE	23	/* populate (prefault) page tables writable */

According to Linux man-pages, the way to tell whether MADV_POPULATE_WRITE is supported on a testing system is:

MADV_POPULATE_WRITE (since Linux 5.14) madvise(0, 0, advice) will return zero iff advice is supported by the kernel and can be relied on to probe for support.

As a result, when we do a syscall madvise(0, 0, 23) on UEKR6 v5.4.17 kernel will return 0 which means supported, while Linux v5.4 mainline returns -1 that means not-supported. The duplicate definition breaks the binary compatibility.

This issue is currently causing a practical failure on OpenJDK. See the ticket JDK-8324776 and discussion upon for details.

Other issue:

Kernel v5.15 on uek7/u2 has a similar problem. The commit https://github.com/oracle/linux-uek/commit/4693c5d9d799eb4803c5afc781cc60e2b645e398 integrated the defs of 22 and 23 from Linux mainline, while used 24 and 25 for the two customized mode numbers.

#define MADV_POPULATE_READ	22	/* populate (prefault) page tables readable */
#define MADV_POPULATE_WRITE	23	/* populate (prefault) page tables writable */
#define MADV_DOEXEC	24		/* do inherit across exec */
#define MADV_DONTEXEC	25		/* don't inherit across exec */

This created another incompatibility against Linux mainline's mode MADV_DONTNEED_LOCKED 24 introduced by https://github.com/torvalds/linux/commit/9457056ac426e5ed0671356509c8dcce69f8dee0 since v5.18-rc1, and mode MADV_COLLAPSE 25 added by https://github.com/torvalds/linux/commit/7d8faaf155454f8798ec56404faca29a82689c77 since v6.1-rc1.

See details at mainline b401b621:

#define MADV_POPULATE_READ	22	/* populate (prefault) page tables readable */
#define MADV_POPULATE_WRITE	23	/* populate (prefault) page tables writable */
#define MADV_DONTNEED_LOCKED	24	/* like DONTNEED, but drop locked pages too */
#define MADV_COLLAPSE	25		/* Synchronous hugepage collapse */

Proposed changes:

Redefine the customized modes MADV_DOEXEC and MADV_DONTEXEC within a separate numerical range, for example 101, 102.

As such it can avoid binary compatibility broken issues, UEK6 and UEK7 can also have same definitions of these two modes, and future UEKs do not need to move them to any new numbers, better for maintenance.

Any other similar or workable solution is also acceptable.

cnqpzhang avatar Feb 23 '24 09:02 cnqpzhang

Thanks for reporting this. I have created an internal ticket to track the issue.

YoderExMachina avatar Feb 23 '24 14:02 YoderExMachina

Thanks, Jeff.

On Sat, 24 Feb 2024 at 01:22, Jeffery Yoder @.***> wrote:

Thanks for reporting this. I have created an internal ticket to track the issue.

— Reply to this email directly, view it on GitHub https://github.com/oracle/linux-uek/issues/23#issuecomment-1961413617, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATMRKAOEHK3A6IB3SYRMQ5LYVCQ4DAVCNFSM6AAAAABDWNMMZSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRRGQYTGNRRG4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

almaclang avatar Feb 24 '24 01:02 almaclang

This is now be fixed in UEK7U2, UEK6U3, and UEK5U5.

YoderExMachina avatar Jun 07 '24 12:06 YoderExMachina