How do I find out whether a message in CBC has padding? When a program is decrypting a message encrypted by CBC mode, what does it find out, whether the last bytes of the last block is part of the padding or part of the plaintext?

Example: Use CBC mode with 4 Byte blocksize and encrypt the following two messages:

m1 = ABCDEF
m2 = ABCDEF22


M1 gets padding and will be "ABCDEF22". How do I find out, whether the original plaintext was ABCDEF, or ABCDEF22?
Actually, that is depending on the padding applied. Maybe there is no padding at all. The implementation defines the padding applied. Check the code or documentation!
The last 22, at first, indicates that might be PKCS#5 or PKCS#7 since PKCS#7 most common with CBC implementations. While PKCS#5 is limited to 8 bytes like DES, PKCS#7 works from 1 to 256 bytes. PKCS#7 appends octets like

For such algorithms, the method shall be to pad the input at the trailing end with $k - (l \bmod k)$ octets all having value $k - (l \bmod k)$, where $l$ is the length of the input.

However, that is 0x02,0x02. The 2s in your last 22 is the character 2 that is in hex 0x32.
To see that has PKCS#7 padding check the last octet and maker sure that the value $k$ of the last octet repeat $k$-times. Example for a 16-byte block cipher where each position is a byte. 1 means 0x01, 2 means 0x02, etc.
xxxxxxxxxxxxxxx1
xxxxxxxxxxxxxx22
xxxxxxxxxxxxx333
...
xFFFFFFFFFFFFFFF
xxxxxxxxxxxxxxxx full block append a new block that contains 16 times 0x10 

To see other padding candidates see Padding in Wikipedia