Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the i386 MPI multiply helper assembly code #1778

Merged
merged 3 commits into from
Jul 20, 2018

Conversation

redtangent
Copy link
Contributor

@redtangent redtangent commented Jun 24, 2018

Description

This is a fix for GitHub issue #1550.

The ebx register was used by the assembly code but not listed in the clobber list, so when the compiler chose to also use it, ebx was getting corrupted. I'm surprised this wasn't spotted sooner.

The fix is very simply to add the ebx register to the clobber list for the i386 inline assembly
for the multiply helper function.

This fixes both i386 and its SSE2 variant which was also broken.

Status

READY

Requires Backporting

Yes
Which branch?
mbedtls-2.1 and mbedtls-2.7. I'll backport once this one's been approved.

Additional comments

This should have been caught by the CI, so I suggest all.sh needs to be extended. (I haven't checked where or how yet).

Todos

  • Tests
  • Documentation
  • Changelog updated
  • Backported

This fix adds the ebx register to the clobber list for the i386 inline assembly
for the multiply helper function.

ebx was used but not listed, so when the compiler chose to also use it, ebx was
getting corrupted. I'm surprised this wasn't spotted sooner.

Fixes Github issues Mbed-TLS#1550.
@simonbutcher simonbutcher added CLA not applicable needs-review Every commit must be reviewed by at least two team members, component-crypto Crypto primitives and low-level interfaces labels Jun 24, 2018
@simonbutcher simonbutcher requested review from mpg, Patater and RonEld June 24, 2018 12:49
@RonEld
Copy link
Contributor

RonEld commented Jun 24, 2018

@redtangent Thank you for your contribution!
Would you mind adding a ChangeLog entry, under Bugfix crediting yourself?

@redtangent
Copy link
Contributor Author

ChangeLog entry added.

RonEld
RonEld previously approved these changes Jun 24, 2018
Patater
Patater previously approved these changes Jun 28, 2018
Copy link
Contributor

@Patater Patater left a comment

Choose a reason for hiding this comment

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

Nice catch!

LGTM

mpg
mpg previously approved these changes Jun 28, 2018
@mpg mpg added needs-backports Backports are missing or are pending review and approval. and removed needs-review Every commit must be reviewed by at least two team members, labels Jun 28, 2018
@simonbutcher
Copy link
Contributor

I've observed this PR doesn't work when CFLAGS='-O0', but works for CFLAGS='-O1' and upwards, therefore marking the PR as needing rework.

@mpg
Copy link
Contributor

mpg commented Jul 3, 2018

I'd like to suggest a resolution: skip the assembly when compiling with -O0 (because if you're doing that, you really shouldn't care about performance). This is already done elsewhere in the file for other reasons.

@simonbutcher
Copy link
Contributor

I agree @mpg. As I've just said in #1810, I think this is the way to go.

We don't compile in the assembly code if compiler optimisations are disabled as
the number of registers used in the assembly code doesn't work with the -O0
option. Also anyone select -O0 probably doesn't want to compile in the assembly
code anyway.
@redtangent redtangent dismissed stale reviews from mpg, Patater, and RonEld via 4b9a3ad July 10, 2018 19:21
@redtangent
Copy link
Contributor Author

redtangent commented Jul 10, 2018

I've updated the PR, to disable the assembly code for -O0, and can confirm it now builds for all values of -O0 to -O3.

@simonbutcher simonbutcher added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Jul 10, 2018
@simonbutcher simonbutcher removed the needs-backports Backports are missing or are pending review and approval. label Jul 10, 2018
@simonbutcher simonbutcher added approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, labels Jul 16, 2018
@simonbutcher
Copy link
Contributor

retest

@simonbutcher simonbutcher merged commit 4b9a3ad into Mbed-TLS:development Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports component-crypto Crypto primitives and low-level interfaces
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants