swapon failed: invalid argument

Bug #1788321 reported by superlex
60
This bug affects 10 people
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Undecided
Unassigned
util-linux (Ubuntu)
Undecided
Unassigned

Bug Description

Environment:
 - Ubuntu 18.04.1 LTS
 - Linux 4.15.0-32-generic i686

Description:
When I try to mount my swap partition or my swap file, I get "swapon failed: invalid argument" .

Steps to reproduce:
1) sudo bash
2) dd if=/dev/zero of=/swapfile bs=1024 count=524288
3) mkswap /swapfile
4) chown root:root /swapfile
5) chmod 0600 /swapfile
6) swapon /swapfile
Last execution returns "swapon failed: invalid argument" .

I'm almost sure it's a bug because I have no problems using Linux 4.15.0-29-generic instead of Linux 4.15.0-32-generic. Also, no problems using Ubuntu 18.04.1 LTS Live CD.

Regards.

CVE References

superlex (e-lex)
description: updated
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better. It seems that your bug report is not filed about a specific source package though, rather it is just filed against Ubuntu in general. It is important that bug reports be filed about source packages so that people interested in the package can find the bugs about it. You can find some hints about determining what package your bug might be about at https://wiki.ubuntu.com/Bugs/FindRightPackage. You might also ask for help in the #ubuntu-bugs irc channel on Freenode.

To change the source package that this bug is filed about visit https://bugs.launchpad.net/ubuntu/+bug/1788321/+editstatus and add the package name in the text box next to the word Package.

[This is an automated message. I apologize if it reached you inappropriately; please just reply to this message indicating so.]

tags: added: bot-comment
Revision history for this message
charlie (chalielinux) wrote :

are you running under vmware? i am hitting this with vmware workstation.

i'm getting this too. i'm running the latest debian kernel and it just started happening.

i'm using a swap partition and have recreated it a few times / run mkswap.

strace swapon -a shows that the syscall swapon('/dev/sdc1', 0) is failing.

man 2 swapon says:

EINVAL
The file path exists, but refers neither to a regular file nor to a block device; or, for swapon(), the indicated path does not contain a valid swap signature or resides on an in-memory file system like tmpfs; or, for swapoff(), path is not currently a swap area.

UBUNTU GUYS -- PLEASE HELP!

superlex (e-lex)
affects: ubuntu → util-linux (Ubuntu)
Revision history for this message
superlex (e-lex) wrote :

Hi charlie,
thank you for your answer.
I confirm I'm using VMware me too.
Last kernel 4.15.0-33 doesn't fix the issue.
Last kernel not affected is 4.15.0-30.

Revision history for this message
charlie (chalielinux) wrote :

i'm running debian.

i'm using 686 (32 bit) and pae. what kernel are you running?

kernel 4.9.0-5 works and 4.9.0-8 is broken (didn't check others).

apt-get changelog linux-image-4.9.0-8-686-pae has lots of swap related notes so they definitely borked something.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in util-linux (Ubuntu):
status: New → Confirmed
Revision history for this message
charlie (chalielinux) wrote :

the changes that broke this seem to be related to the L1 terminal patches. i've linked the CVE numbers. maybe that will get us some help.

Changed in linux (Ubuntu):
status: New → Confirmed
Revision history for this message
superlex (e-lex) wrote :

Charlie,
as regards me:

- Ubuntu 18.04
- Linux 4.15.0-33-generic #36-Ubuntu GNU/Linux
- util-linux|mount 2.31.1-0.4ubuntu3.1
affected

- Ubuntu 16.04
- Linux 4.15.0-33-generic #36~16.04.1-Ubuntu GNU/Linux
- util-linux|mount 2.27.1-6ubuntu3.6
not affected

tags: added: regression-update
Changed in linux (Ubuntu):
status: Confirmed → Incomplete
Revision history for this message
Phillip Susi (psusi) wrote :

This doesn't happen on amd64. Do you also have to re-run mkswap when switching back to the older, working kernel, or does simply using the other kernel let you run swapon on the same file that doesn't work with the newer kernel?

Changed in linux (Ubuntu):
status: Incomplete → Confirmed
Changed in util-linux (Ubuntu):
status: Confirmed → Invalid
Revision history for this message
Phillip Susi (psusi) wrote :

Also what does getconf PAGESIZE say under the broken kernel?

Revision history for this message
superlex (e-lex) wrote :

>> Do you also have to re-run mkswap when switching back to the older, working kernel, or does simply using the other kernel let you run swapon on the same file that doesn't work with the newer kernel?

Nope, same swap file / swap partition, without have to re-run mkswap.

>> Also what does getconf PAGESIZE say under the broken kernel?

Both kernel say 4096 .

Revision history for this message
Roman Fiedler (roman-fiedler-deactivatedaccount) wrote :

This is the failing "swapon" sequence from updated Xenial i386 on vmware:

3915 open("/dev/sda2", O_RDONLY|O_LARGEFILE) = 3
3915 uname({sysname="Linux", nodename="v3ls1717", ...}) = 0
3915 ioctl(3, BLKGETSIZE64, [535822336]) = 0
3915 read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 65536) = 65536
3915 close(3) = 0
3915 swapon("/dev/sda2", 0) = -1 EINVAL (Invalid argument)

Sequence is identical to other, native/amd64 system with same kernel version but without the problem where swapon() will return 0.

Revision history for this message
Mathias (go4) wrote :

Swapon is not working with swap file or swap partion. Mkswap with Kernel 4.15.0-30-gernic and swapon with Kernel 4.15.0-33-gernic is even not working.

VMware ESXi 6.0 + Ubuntu 18.04 (32Bit)
- Linux 4.15.0-33-generic (i686)
affected

VMware ESXi 6.0 + Ubuntu 18.04 (32Bit)
- Linux 4.15.0-30-generic (i686)
not affected

VMware ESXi 6.0 + Ubuntu 18.04 (64Bit)
- Linux 4.15.0-33-generic (x86_64)
not affected

Revision history for this message
Roman Fiedler (roman-fiedler-deactivatedaccount) wrote :

On Xenial, update to "linux-image-4.4.0-135-generic 4.4.0-135.161" did not fix the problem, but I noticed a message, that might be related to the issue:

[ 3.083083] Truncating oversized swap area, only using 0k out of 261116k

Revision history for this message
Roman Fiedler (roman-fiedler-deactivatedaccount) wrote :

Maybe this is the fix:
x86/speculation/l1tf: fix overflow on l1tf_pfn_limit() on 32bit
https://lkml.org/lkml/2018/8/20/222

Revision history for this message
Lutz Schwarz (blacky32) wrote :

I am running

Linux 4.4.0-135-generic #161~14.04.1-Ubuntu SMP Tue Aug 28 11:19:03 UTC 2018 GNU/Linux

as a virtual machine in VMWare and got the same problem with swapon.

Revision history for this message
John Shipp (shippj) wrote :

My perspective suggests that this bug might have came from upsteam.

I'm running DEBIAN 9 in VMware Workstation 12.5.9 build-7535481 and having this exact same issue.

AFFECTED = Linux 4.9.0-8-686-pae #1 SMP Debian 4.9.110-3+deb9u4 (2018-08-21) i686 GNU/Linux

NOT affected = Linux 4.9.0-7-686-pae #1 SMP Debian 4.9.110-3+deb9u2 (2018-08-13) i686 GNU/Linux

Revision history for this message
superlex (e-lex) wrote :

Last kernel 4.15.0-36-generic #39-Ubuntu i686 fixes the issue for me.
Could you try, please?

Revision history for this message
Lucian Ion (lucianio) wrote :

fixed for me as well, thanks
Linux svn-desktop16 4.15.0-36-generic #39~16.04.1-Ubuntu SMP Tue Sep 25 09:00:45 UTC 2018 i686 i686 i686 GNU/Linux
$ free
              total used free shared buff/cache available
Mem: 1022124 244104 112896 14520 665124 594404
Swap: 1047548 4616 1042932

Revision history for this message
Lutz Schwarz (blacky32) wrote :

Seems fixed for

Linux 4.4.0-137-generic #163~14.04.1-Ubuntu SMP Mon Sep 24 17:13:32 UTC 2018 i686 i686 GNU/Linux

Thank you.

Revision history for this message
WIll Salmon (will-salmon) wrote :

Like John Shipp, we are on Debian 9.4 32-bit (on VMware) and still have this issue on the latest kernel: 4.9.0-8-686-pae #1 SMP Debian 4.9.110-3+deb9u6 (2018-10-08)

Message in syslog is :
 swapon: /dev/sdb1: swapon failed: Invalid argument

To work round it, I've pinned kernel at 4.9.0-7 on production VMs with an apt/preferences.d/ file. - see also Debian bug #907175

Cheers

Revision history for this message
utnubudnai (duxiutao-gmail) wrote :

ubuntu 16.04, hit the same issue as this. swapon -v shows these:

```
swapon: /my/swap: found swap signature: version 1d, page-size 4, same byte order
swapon: /my/swap: pagesize=4096, swapsize=13..., devsize=13....
swapon: /my/swap: swapon failed: Invalid argument
```

Brad Figg (brad-figg)
tags: added: cscc
Revision history for this message
Hugh Buntu (hughbuntu) wrote :

Getting the same error on old bare metal:

4.15.0-88-generic #88-Ubuntu SMP Tue Feb 11 20:11:34 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Pentium(R) Dual CPU T3400 @ 2.16GHz
stepping : 13
microcode : 0xa4
cpu MHz : 1290.104
cache size : 1024 KB

~# swapon -a
swapon: /swapfile: swapon failed: Invalid argument

Swap partition also does not mount at boot.
I can run gparted, hit "swapon" on the right-click menu for the swap partition, and it mounts.

I don't have this problem on other harware/VMs with same build & procedures.

Revision history for this message
clickwir (clickwir) wrote :

Just did a fresh install of 20.04 as a Proxmox VM and see this "invalid argument" in the start up messages and syslog. Trying to start it manually also fails. Tried recreating it, also failed.

root@changeme:/# fallocate -l 2G /swap.img
root@changeme:/# chmod 600 /swap.img
root@changeme:/# ls -lah /swap.img
-rw------- 1 root root 2.0G Apr 24 04:07 /swap.img
root@changeme:/# mkswap /swap.img
mkswap: /swap.img: warning: wiping old swap signature.
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=bd9bdc4f-4c53-4b0b-ad92-687ed5f669e6
root@changeme:/# swapon /swap.img
swapon: /swap.img: swapon failed: Invalid argument
root@changeme:/# swapon -v /swap.img
swapon: /swap.img: found signature [pagesize=4096, signature=swap]
swapon: /swap.img: pagesize=4096, swapsize=2147483648, devsize=2147483648
swapon /swap.img
swapon: /swap.img: swapon failed: Invalid argument

Revision history for this message
clickwir (clickwir) wrote :

Fixed my problem.

While looking through /var/log/syslog, I noticed this line around the same time swap mount failed.

BTRFS warning (device sda3): swapfile must not be copy-on-write

Then a few lines later...

systemd[1]: swap.img.swap: Failed with result 'exit-code'.
systemd[1]: Failed to activate swap /swap.img.
systemd[1]: Dependency failed for Swap.
systemd[1]: swap.target: Job swap.target/start failed with result 'dependency'.

Yes my root is on btrfs and I did not see this error before. So I deleted /swap.img and started over.

$ sudo rm -rf /swap.img
$ sudo touch /swap.img
$ sudo chattr +C /swap.img
$ sudo fallocate -l 2G /swap.img
$ sudo chmod 600 /swap.img
$ sudo mkswap /swap.img
$ sudo swapon /swap.img

No error and "swapon --show" gives this:

NAME TYPE SIZE USED PRIO
/swap.img file 2G 0B -2

Just what I was expecting. So problem solved for me, maybe a check can be put in to see if it's on btrfs and apply the 'chattr +C' option.

Revision history for this message
Mélodie (meets) wrote :

Hello,

thanks to clickwir, this has helped me solve it in Ubuntu 20.04 with btrfs!

Best regards,
Mélodie

Revision history for this message
Simon Shapiro (sheemon-lists) wrote :

Good News!

This bug is still here. Same error on

Dell Inspiron 13-7353, Ubuntu 20.04.1 (Upgraded from 18.05.5),
Kernel:

Linux NOMIS-inspiron 5.4.0-47-generic #51-Ubuntu SMP Fri Sep 4 19:50:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Filesystem btrfs, Storage: Samsung 650 SSD (1TB).
Was working properly on 18.04, and 20.04.1 on earlier kernels.
I did not try late kernels.

It seems like I have the worst combination of configuration but innocently walked into this .

I reduced vm.swapiness to ZERO. in the hope I will encouner fewer crashes.

Please advise.

Thanx.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers