A personal foul by a defensive player is covered in Section I of Rule 12b of the NBA rules:
Contact initiated by the defensive player guarding a player with the
ball is not legal. This contact includes, but is not limited to,
forearm, hands, or body check.
However, there are a list of exceptions that accompany this rule, which answers what a defender is allowed to do.
EXCEPTIONS:
(1) A defender may apply
contact with a forearm to an offensive player with the ball who has
his back to the basket below the free throw line extended outside the
Lower Defensive Box.
(2) A defender may apply contact with a forearm
and/or one hand with a bent elbow to an offensive player in a post-up
position with the ball in the Lower Defensive Box.
(3) A defender may
apply contact with a forearm to an offensive player with the ball at
any time in the Lower Defensive Box. The forearm in the above
exceptions is solely for the purpose of maintaining a defensive
position.
(4) A defender may position his leg between the legs of an
offensive player in a post-up position in the Lower Defensive Box for
the purpose of maintaining defensive position. If his foot leaves the
floor in an attempt to dislodge his opponent, it is a foul
immediately.
(5) Incidental contact with the hand against an offensive
player shall be ignored if it does not affect the player’s speed,
quickness, balance and/or rhythm
Comment 2C on the rules also addresses what a defender is allowed to do:
BLOCK-CHARGE
A defensive player is permitted to establish a legal
guarding position in the path of a dribbler regardless of his speed
and distance.
A defensive player is not permitted to move into the
path of an offensive player once he has started his upward motion to
attempt a field goal or pass.
A defensive player must allow a moving
player the opportunity to avoid contact when the offensive player
receives a pass outside the lower defensive box. The lower defensive
box is the area between the 3-foot posted-up marks, the bottom tip of the circle and the endline.
A defensive player must allow an
airborne player the opportunity to land and then avoid contact when
the offensive player is outside the lower defensive box.
A defensive
player is permitted to establish a legal guarding position in the path
of an offensive player who receives a pass inside the lower defensive
box regardless of his speed and distance.
A defensive player must
allow an airborne player who receives a pass the space to land when
the offensive player is inside the lower defensive box.