Skip to content

FIX: enforce POSIX native binary hardening - #810

Merged
Sumit Sarabhai (sumitmsft) merged 8 commits into
mainfrom
sumitsar/fix-cf041-native-hardening
Nov 19, 2026
Merged

Sumit Sarabhai (sumitmsft) merged 8 commits into
mainfrom
sumitsar/fix-cf041-native-hardening

Conversation

@sumitmsft

@sumitmsft Sumit Sarabhai (sumitmsft) commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • default single-config POSIX builds to Release when no build type is supplied
  • enable stack protection for the native extension on POSIX
  • select _FORTIFY_SOURCE=3 when supported, otherwise level 2, excluding Debug builds
  • enable full RELRO, immediate binding, and non-executable stack declarations on Linux
  • add source-contract, ELF parser, and loaded-extension regression tests

The hardening options are private to ddbc_bindings; simdutf compilation is unchanged. macOS retains its existing dynamic-link behavior, and Windows behavior is unchanged.

Validation

  • Windows x64 native build
  • 37 passed, 4 expected platform skips
  • import, formatting, and diff checks
  • hosted CI will validate manylinux, musllinux, ARM64, macOS, and Clang coverage

AB#48377

AB#48377

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 23, 2026 18:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

ELF linker flags must be restricted to Linux targets to avoid unsupported options on other UNIX platforms.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

This PR strengthens POSIX native-extension binary hardening and adds regression coverage.

Changes:

  • Defaults single-config builds to Release.
  • Adds compiler and linker hardening flags.
  • Adds source-contract and ELF validation tests.
File Summary
tests/​test_040_native_binary_hardening.py Verifies hardening configuration and Linux ELF properties.
mssql_python/​pybind/​CMakeLists.txt Configures build defaults and native hardening flags.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread mssql_python/pybind/CMakeLists.txt Resolved
@github-actions github-actions Bot added the pr-size: medium Moderate update size label Sep 23, 2026
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

86%


📈 Total Lines Covered: 11800 out of 13687
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

No lines with coverage information in this diff.


📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.performance_counter.hpp: 0.7%
mssql_python.pybind.logger_bridge.cpp: 57.9%
mssql_python.pybind.ddbc_bindings.h: 64.5%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python._native_fetch.py: 77.7%
mssql_python.pybind.ddbc_bindings.cpp: 81.4%
mssql_python.pybind.row_mapping_cache.hpp: 81.5%
mssql_python.pybind.connection.connection_pool.cpp: 82.5%
mssql_python.pybind.connection.connection.cpp: 83.1%
mssql_python.logging.py: 86.8%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

Give each concurrent connect call its own configured native connection mock so MagicMock child creation cannot race during close.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 24, 2026 06:18
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

PR Performance Report

✅ No regression detected

No consistent slowdowns detected across all 2 environments.

0 IMPROVEMENTS 0 SLOWDOWNS 2/2 ENVIRONMENTS

Coverage: 2 of 2 environments completed. Advisory result; does not block merging.

Performance diagnostics

Phase times are inclusive diagnostics and must not be added together. They identify where measured time changed, not why it changed.

No affected phases or call-count changes were recorded.

All database tasks and timings

Unix / SQL Server 2022

Database task Before After Paired change Result
Connection opening 10.787 ms 10.780 ms -0.1% no signal
SELECT queries 1.014 ms 1.015 ms -1.4% no signal
Row insertion 30.948 ms 30.530 ms -1.5% no signal
Executemany inserts 165.672 ms 164.271 ms -0.7% no signal
Fetch-all queries 125.088 ms 121.386 ms -3.0% no signal
Row-by-row fetching 4.988 ms 4.965 ms +0.8% no signal
Batched row fetching 121.270 ms 118.377 ms -2.4% no signal
Transaction commit and rollback 106.451 ms 105.719 ms -0.2% no signal
Arrow row fetching 90.823 ms 89.849 ms -1.7% no signal
100,000-row insertion 367.075 ms 361.328 ms -2.7% no signal
Row fetching in batches of 100 121.366 ms 121.642 ms +1.3% no signal
Row fetching in batches of 10,000 130.504 ms 144.756 ms -1.6% no signal
Repeated positional queries 32.039 ms 32.059 ms -0.5% no signal
Repeated named-parameter queries 32.926 ms 33.127 ms +0.9% no signal
Legacy 100,000-row insertion 260.931 ms 279.828 ms +1.3% no signal
Insertion with explicit input sizes 410.506 ms 406.940 ms +1.4% no signal
Joined aggregation queries 182.351 ms 183.025 ms +0.4% no signal
Large joined-result fetching 203.317 ms 199.054 ms -0.5% no signal
1.2-million-row fetching 3555.307 ms 3526.970 ms -0.1% no signal
Common table expression queries 5.552 ms 5.502 ms -0.7% no signal
256 KiB VARCHAR(MAX) / fetchall() 1.596 ms 1.554 ms -3.1% no signal
10,000 scalar values / fetchval() (debug disabled) 17.095 ms 17.174 ms +0.6% no signal
10,000 output-converted rows / fetchall() 20.497 ms 19.829 ms -2.8% no signal
10,000 output-converted rows / fetchmany(1000) 24.540 ms 25.220 ms +1.9% no signal
10,000 INT/NVARCHAR rows / fetchmany(1) 25.333 ms 24.674 ms -2.6% no signal
10,000 rows x 32 columns / dict(row._mapping) (warm) 33.460 ms 32.432 ms -5.8% no signal

Unix / SQL Server 2025

Database task Before After Paired change Result
Connection opening 81.420 ms 81.271 ms +0.4% no signal
SELECT queries 0.980 ms 0.966 ms -2.6% no signal
Row insertion 29.137 ms 29.324 ms +0.6% no signal
Executemany inserts 137.161 ms 136.658 ms -2.0% no signal
Fetch-all queries 118.079 ms 118.970 ms +0.1% no signal
Row-by-row fetching 4.758 ms 4.742 ms -0.5% no signal
Batched row fetching 110.524 ms 109.645 ms -0.9% no signal
Transaction commit and rollback 101.547 ms 101.500 ms -1.4% no signal
Arrow row fetching 85.824 ms 88.170 ms +3.1% no signal
100,000-row insertion 320.472 ms 326.431 ms +2.3% no signal
Row fetching in batches of 100 107.067 ms 107.364 ms +0.9% no signal
Row fetching in batches of 10,000 122.149 ms 143.374 ms +16.5% no signal
Repeated positional queries 29.784 ms 30.126 ms +2.0% no signal
Repeated named-parameter queries 30.420 ms 30.012 ms -1.4% no signal
Legacy 100,000-row insertion 228.768 ms 230.057 ms -0.1% no signal
Insertion with explicit input sizes 370.307 ms 371.759 ms +2.5% no signal
Joined aggregation queries 172.783 ms 172.970 ms -0.3% no signal
Large joined-result fetching 192.343 ms 191.550 ms +2.8% no signal
1.2-million-row fetching 3511.960 ms 3481.099 ms -0.9% no signal
Common table expression queries 5.420 ms 5.381 ms +1.1% no signal
256 KiB VARCHAR(MAX) / fetchall() 1.454 ms 1.360 ms -10.3% no signal
10,000 scalar values / fetchval() (debug disabled) 16.628 ms 16.631 ms +2.7% no signal
10,000 output-converted rows / fetchall() 19.344 ms 18.827 ms -2.7% no signal
10,000 output-converted rows / fetchmany(1000) 24.612 ms 23.477 ms -3.4% no signal
10,000 INT/NVARCHAR rows / fetchmany(1) 24.218 ms 24.419 ms +0.1% no signal
10,000 rows x 32 columns / dict(row._mapping) (warm) 32.018 ms 33.058 ms +4.2% no signal
Build and measurement details

ADO build 193592

PR head: 7538791892505ebbfdbfc67a2d542f3ff5e81296
Base: dd4f1e7078944cb2e5261a59333de9667b65eac6
Measured merge: 08509e909ea1ff54baf015179b055d082642e106

  • Unix / SQL Server 2022: Python 3.12.3, x86_64, SQL 16.0.4325.4; 5 paired comparisons and 1 warmup.
  • Unix / SQL Server 2025: Python 3.12.3, x86_64, SQL 17.0.5065.9; 5 paired comparisons and 1 warmup.

A consistent change requires more than 20% median paired movement, at least 1 ms between the median runtimes, and at least 80% of pairs exceeding the relative threshold in the same direction. A slowdown without enough pair agreement is reported as inconsistent.

The displayed change is the median of paired before-and-after ratios. It is not recalculated from the two displayed median runtimes.

Both revisions use profiling-enabled builds on the same agent and database, with alternating order and discarded warmups. Results are diagnostic and do not represent production-wheel latency.

Raw samples and logs are attached to the ADO run as profiler-* artifacts.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Native build and ELF hardening changes span multiple platforms and warrant final human validation.

Review effort: Lite
Findings: 1 High severity

Open (1)
@sumitmsft
Sumit Sarabhai (sumitmsft) marked this pull request as ready for review September 24, 2026 07:54
Copilot AI review requested due to automatic review settings September 24, 2026 09:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved blocking issues were identified.

Review effort: Lite
Findings: None

Resolved since last review (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The hardening test must skip when the native extension is unavailable in source-only checkouts.

Review effort: Lite
Findings: None

Copilot AI review requested due to automatic review settings September 25, 2026 06:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified.

Review effort: Lite
Findings: None

Gaurav Sharma (bewithgaurav) added a commit that referenced this pull request Oct 12, 2026
Remove the native-hardening and auth-test changes owned by PR #810, retaining only the Python 3.15 header-order compatibility flag and its focused contract.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Gaurav Sharma (bewithgaurav) added a commit that referenced this pull request Oct 12, 2026
### Summary

Adds Python 3.15 validation while keeping every existing PR-validation
leg enabled.

- Validates Python 3.15 GA on Windows x64 and macOS x86_64 through the
hosted Python toolcache.
- Keeps Linux x86_64 and Linux ARM64 on RC3 until the official
`python:3.15.0-bookworm` image is published.
- Uses PyArrow 25.0.1 below Python 3.15 and stable PyArrow 26.0.0 on
Python 3.15+.
- Handles Python 3.15 POSIX feature macros, Decimal conversion traceback
privacy, and cyclic-GC finalization ordering.
- Inherits the stable ABI `mssql-python-rs 0.3.0` installer contract
merged in #804.

### Validation

- Python 3.15.0 is marked stable in the hosted Python toolcache.
- Stable PyArrow 26.0.0 publishes `cp315` wheels for every target
platform.
- Focused pipeline and hardening contracts: 9 passed, 6 platform skips.
- Python 3.10 release locks continue to resolve PyArrow 25.0.1.

### Follow-up

Move both Linux legs from RC3 to GA once the official Bookworm image is
published. The native hardening changes overlap with #810; pull `main`
again after #810 merges.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Sumit Sarabhai <sumitsar@microsoft.com>
Resolve native hardening and Python 3.15 build configuration overlap; preserve isolated native auth mocks and thread-safe credential assertions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings November 18, 2026 14:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Cross-platform compiler and linker hardening changes require hosted Linux, musl, ARM64, and macOS builds to verify configure compatibility and shipped binary properties beyond the available source-level evidence.

No open issues 🎉

Review effort: Lite

Keep POSIX compile hardening unchanged and assert the Linux-only linker scope in the existing source-contract regression test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings November 18, 2026 19:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Approval should wait for hosted Linux, ARM64, musl, and macOS builds plus ELF/Mach-O and extension-import checks, since the supplied validation covers only Windows.

No open issues 🎉

Review effort: Lite

Copilot AI lite review requested due to automatic review settings November 19, 2026 10:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Hosted CI and artifact validation is still needed to confirm that the compiler/linker hardening flags are accepted and present in binaries across the supported Linux, musl, ARM64, and macOS toolchains.

No open issues 🎉

Review effort: Lite

@sumitmsft
Sumit Sarabhai (sumitmsft) merged commit 52f3001 into main Nov 19, 2026
38 checks passed
Jahnvi Thakkar (jahnvi480) added a commit that referenced this pull request Nov 27, 2026
### Work Item / Issue Reference
<!--
IMPORTANT: Please follow the PR template guidelines below.
For mssql-python maintainers: Insert your ADO Work Item ID below
For external contributors: Insert Github Issue number below
Only one reference is required - either GitHub issue OR ADO Work Item.
-->

<!-- mssql-python maintainers: ADO Work Item -->
>
[AB#50319](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/50319)

<!-- External contributors: GitHub Issue -->

-------------------------------------------------------------------
### Summary
<!-- Insert your summary of changes below. Minimum 10 characters
required. -->

Prepare mssql-python 1.19.0. Bump the package version in
`mssql_python/__init__.py` and `setup.py`, and replace the previous
release highlights in `PyPI_Description.md`.

#### Enhancements

- Optional connection retry policy for transient failures during
connection initialization (#751).
- Table-valued parameter definitions and synchronous execution through
the default ODBC provider (#789).
- Optional SQLSTATE and native error number attributes on DB-API
exceptions (#909, #913).
- Best-effort synchronous cursor cancellation with operation-scoped
requests and checked recovery (#911, #915).
- POSIX native binary hardening (#810).

#### Bug Fixes

- Lossless `executemany` inference for Unicode, Decimal, mixed-type
batches, and embedded/trailing NULs (#907).
- Numeric binding for auto-detected money-range Decimal batches (#752).
- Restore Korean VARCHAR conversion fidelity in manylinux packages
(#910).

#### Release status and gates

- ADO-GitHub synchronization completed into ADO `main` via [ADO PR
!9120](https://sqlclientdrivers.visualstudio.com/mssql-python/_git/mssql-python/pullrequest/9120).
- Ready for reviewer approval. The equivalent ADO release PR follows
approval of this GitHub PR.
- Do not merge this release PR until the required PyPI and Conda
publication and verification gates are complete.
- Release builds, publication, and release qualification remain
outstanding; marking this PR ready for review does not authorize
publication or merging.

#### Validation

- `.\.venv\Scripts\python.exe -m pre_commit run black-check --all-files
--hook-stage pre-push` - passed.
- `git diff --check` - passed.
- Source-only checks verified matching `1.19.0` version declarations,
one current "What's new" section, and the agreed description scope.
- Native build and runtime pytest were not run for this
version/description-only change; release qualification remains required.

<!--
### PR Title Guide

> For feature requests
FEAT: (short-description)

> For non-feature requests like test case updates, config updates ,
dependency updates etc
CHORE: (short-description)

> For Fix requests
FIX: (short-description)

> For doc update requests
DOC: (short-description)

> For Formatting, indentation, or styling update
STYLE: (short-description)

> For Refactor, without any feature changes
REFACTOR: (short-description)

> For performance improvements
PERF: (short-description)

> For AI tooling, agents, skills, prompts, or AI-assisted development
workflows
AI: (short-description)

> For release related changes, without any feature changes
RELEASE: #<RELEASE_VERSION> (short-description)

### Contribution Guidelines

External contributors:
- Create a GitHub issue first:
https://github.com/microsoft/mssql-python/issues/new
- Link the GitHub issue in the "GitHub Issue" section above
- Follow the PR title format and provide a meaningful summary

mssql-python maintainers:
- Create an ADO Work Item following internal processes
- Link the ADO Work Item in the "ADO Work Item" section above
- Follow the PR title format and provide a meaningful summary
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: medium Moderate update size

4 participants